我已经集成了一个模块,用户可以在网站上传图像,并可以根据自己的需要裁剪图像。但是,我正在使用该裁剪模块用于商务目的。我希望人们可以自己裁剪并上传他们的裁剪图像,以便我们可以根据该图像制作蛋糕。
$output_filename=$output_directory.$uniquename.$type;
$inc=0;
while(@getimagesize($output_filename))
$output_filename = $output_directory.$uniquename.$inc++;
// resize the original image to size of editor
$resizedImage = imagecreatetruecolor($imgW, $imgH);
$cropped_rotated_image = imagecreatetruecolor($imgW, $imgH);
$final_image=imagecreatetruecolor($cropW,$cropH);
imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH);
// rotate the rezized image
$rotated_image = imagerotate($resizedImage, -$angle, 0);
// find new width & height of rotated image
$rotated_width = imagesx($rotated_image);
$rotated_height = imagesy($rotated_image);
// diff between rotated & original sizes
$dx = $rotated_width - $imgW;
$dy = $rotated_height - $imgH;
// crop rotated image to fit into original rezized rectangle
imagecolortransparent($cropped_rotated_image, imagecolorallocate($cropped_rotated_image, 0, 0, 0));
imagecopyresampled($cropped_rotated_image, $rotated_image, 0, 0, $dx / 2, $dy / 2, $imgW, $imgH, $imgW, $imgH);
// crop image into selected area
//$final_image = imagecreatetruecolor($cropW, $cropH);
imagecolortransparent($final_image, imagecolorallocate($final_image, 0, 0, 0));
imagecopyresampled($final_image, $cropped_rotated_image, 0, 0, $imgX1, $imgY1, $cropW, $cropH, $cropW, $cropH);
// finally output png image
imagepng($final_image, $output_filename, $png_quality);
//imagejpeg($final_image,$output_filename, $jpeg_quality);
$response = Array(
"status" => 'success',
"url" => '/'.$output_filename,
);
imagedestroy($final_image);
原始图片:
裁剪图像的尺寸为500X500,现在的问题是原始图像的质量很好,但裁剪的图像有点褪色。我尝试使用图像卷积,但它也没有帮助。如何做我提高裁剪图像的质量?
我尝试的代码:
$sharpen = array(
array(-1, -1, -1),
array(-1, 16, -1),
array(-1, -1, -1),
// );
// calculate the sharpen divisor
$divisor = array_sum(array_map('array_sum', $sharpen));
// apply the matrix
imageconvolution($final_image, $sharpen, $divisor, 0);
注意:
裁剪器的固定宽度和高度意味着裁剪后的图像总是500X500。
原始图片的尺寸大于500X500。