App-cdnget

 view release on metacpan or  search on metacpan

lib/App/cdnget/Downloader.pm  view on Meta::CPAN

}

sub processHook_img
{
	my $self = shift;
	my ($hook, $response, @params) = @_;
	my $headers = $response->{_headers};
	my $img;
	given ($headers->content_type)
	{
		when ("image/png")
		{
			$img = GD::Image->newFromPngData($response->decoded_content) or $self->throw($!);
		}
		when ("image/jpeg")
		{
			$img = GD::Image->newFromJpegData($response->decoded_content) or $self->throw($!);
		}
		default
		{
			$self->throw("Unsupported content type for image");

lib/App/cdnget/Downloader.pm  view on Meta::CPAN

		when (/^imgresize$/i)
		{
			$params[0] = $img->width unless defined($params[0]) and $params[0] > 0 and $params[0] <= 10000;
			$params[1] = $img->height unless defined($params[1]) and $params[1] > 0 and $params[1] <= 10000;
			$params[2] = 60 unless defined($params[2]) and $params[2] >= 0 and $params[2] <= 100;
			my $newimg = new GD::Image($params[0], $params[1]) or $self->throw($!);
			$newimg->copyResampled($img, 0, 0, 0, 0, $params[0], $params[1], $img->width, $img->height);
			my $data;
			given ($headers->content_type)
			{
				when ("image/png")
				{
					$data = $newimg->png($params[2]) or $self->throw($!);
				}
				when ("image/jpeg")
				{
					$data = $newimg->jpeg($params[2]) or $self->throw($!);
				}
			}
			return ("Status: 200\r\nContent-Type: ".$headers->content_type."\r\nContent-Length: ".length($data)."\r\n", $data);
		}
		when (/^imgcrop$/i)
		{
			$params[0] = $img->width unless defined($params[0]) and $params[0] > 0;
			$params[1] = $img->height unless defined($params[1]) and $params[1] > 0;
			$params[2] = 0 unless defined($params[2]) and $params[2] > 0;
			$params[3] = 0 unless defined($params[3]) and $params[3] > 0;
			$params[4] = 60 unless defined($params[4]) and $params[4] >= 0 and $params[4] <= 100;
			my $newimg = new GD::Image($params[0], $params[1]) or $self->throw($!);
			$newimg->copy($img, 0, 0, $params[2], $params[3], $params[0], $params[1]);
			my $data;
			given ($headers->content_type)
			{
				when ("image/png")
				{
					$data = $newimg->png($params[4]) or $self->throw($!);
				}
				when ("image/jpeg")
				{
					$data = $newimg->jpeg($params[4]) or $self->throw($!);
				}
			}
			return ("Status: 200\r\nContent-Type: ".$headers->content_type."\r\nContent-Length: ".length($data)."\r\n", $data);
		}
		default
		{



( run in 2.806 seconds using v1.01-cache-2.11-cpan-df04353d9ac )