$width)$maxwidth = $width; if($maxheight>$height)$maxheight = $height; } if ($height > $width) { $ratio = $maxheight / $height; $newheight = $maxheight; $newwidth = $width * $ratio; } else { $ratio = $maxwidth / $width; $newwidth = $maxwidth; $newheight = $height * $ratio; } $newimg = imagecreatetruecolor($newwidth,$newheight); $palsize = ImageColorsTotal($img); for ($i = 0; $i < $palsize; $i++) { $colors = ImageColorsForIndex($img, $i); ImageColorAllocate($newimg, $colors['red'], $colors['green'], $colors['blue']); } imagefill($newimg, 0, 0, IMG_COLOR_TRANSPARENT); imagesavealpha($newimg,true); imagealphablending($newimg, true); imagecopyresampled($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); $img = $newimg; } function filter(&$im,$vars) { foreach($vars as $var) { if(strpos($var,'_')) { $a = explode('_',$var); $var = $a[0]; $val = $a[1]; } switch($var) { case 'negative': imagefilter($im,IMG_FILTER_NEGATE); break; case 'grayscale': imagefilter($im,IMG_FILTER_GRAYSCALE); break; case 'brightness': imagefilter($im,IMG_FILTER_BRIGHTNESS,$val); break; case 'edgedetect': imagefilter($im,IMG_FILTER_EDGEDETECT); break; case 'smooth': imagefilter($im,IMG_FILTER_SMOOTH,$val); break; case 'contrast': imagefilter($im,IMG_FILTER_CONTRAST,$val); break; case 'pixelate': imagefilter($im,IMG_FILTER_PIXELATE,$val); break; } } } }