$sourceW) && ($destH > $sourceH)) { $destW = $sourceW; $destH = $sourceH; $sharpen = false; } else { $r = $sourceW / $sourceH; if ($destW / $destH > $r) $destW = floor($destH * $r); else $destH = floor($destW / $r); } } // print "\$left = $left, \$top = $top, \$destW = $destW, \$destH = $destH, \$sourceW = $sourceW, \$sourceH = $sourceH"; $dest_image = imagecreatetruecolor($destW, $destH); // Lessen the effect of a filter by increasing the value in the center cell; // compensate with the appropriate Divisor to maintain the brightness of the original image. // $sharpenMatrix = array(array(-1,-1,-1),array(-1,16,-1),array(-1,-1,-1)); // $divisor = 8; // $offset = 0; // Sharpen the image based on two things: // (1) the difference between the original size and the final size // (2) the final size $sharpness = FindSharpness($sourceW, $destW); $sharpenMatrix = array( array(-1, -2, -1), array(-2, $sharpness + 12, -2), array(-1, -2, -1) ); $divisor = $sharpness; $offset = 0; //check if image is a jpeg or png if ($Image_type == IMAGETYPE_JPEG) { imagecopyresampled($dest_image, $source_image, 0, 0, $left, $top, $destW, $destH, $sourceW, $sourceH); if ($sharpen) imageconvolution($dest_image, $sharpenMatrix, $divisor, $offset); imagejpeg($dest_image, $newfile); } else if ($Image_type == IMAGETYPE_PNG) { imagealphablending($dest_image, false); imagecopyresampled($dest_image, $source_image, 0, 0, $left, $top, $destW, $destH, $sourceW, $sourceH); if ($sharpen) imageconvolution($dest_image, $sharpenMatrix, $divisor, $offset); imagesavealpha($dest_image, true); imagepng($dest_image, $newfile); } imagedestroy($dest_image); } imagedestroy($source_image); return true; } // function from Ryan Rud (http://adryrun.com) function FindSharpness($orig, $final) { $final = $final * (750.0 / $orig); $a = 52; $b = -0.27810650887573124; $c = .00047337278106508946; $result = $a + $b * $final + $c * $final * $final; return max(round($result), 0); } ?>