我正在使用一个名为“jcrop”的插件,它非常好,你可以在这里看到它:
http://howhack.com/crop/demos/crop2.php
问题是这个插件不支持具有透明背景的 png。
javascript / jQuery中是否有类似的脚本/插件支持具有透明背景的png?
我需要这个长宽比为 16:9 且最终图像始终为 640x360 的矩形,这就是我尝试使用这个“jcrop”的原因。
我正在使用一个名为“jcrop”的插件,它非常好,你可以在这里看到它:
http://howhack.com/crop/demos/crop2.php
问题是这个插件不支持具有透明背景的 png。
javascript / jQuery中是否有类似的脚本/插件支持具有透明背景的png?
我需要这个长宽比为 16:9 且最终图像始终为 640x360 的矩形,这就是我尝试使用这个“jcrop”的原因。
我假设插件通过 PHP 在服务器上编辑图像?如果是这样,您需要进行一些特殊调用以保留 PNG 图像中的 alpha 透明度:
$x = $_GET["x"];
$y = $_GET["y"];
$w = $_GET["w"];
$h = $_GET["h"];
// Load the original image.
$img = imagecreatefrompng($img_path);
imagealphablending($img, true);
// Create a blank canvas for the cropped image.
$img_cropped = imagecreatetruecolor($w, $h);
imagesavealpha($img_cropped, true);
imagealphablending($img_cropped, false);
$transparent = imagecolorallocatealpha($img_cropped, 0, 0, 0, 127);
imagefill($img_cropped, 0, 0, $transparent);
// Crop the image and store the data on the blank canvas.
imagecopyresampled($img_cropped, $img, 0, 0, $x, $y, $w, $h, $w, $h); // or imagecopy()
// Save the image.
imagepng($img_cropped, "image_cropped.png", 2);
// Free memory.
imagedestroy($img);
imagedestroy($img_cropped);
这在此处讨论 PHP 的 imagecopyresampled() 时曾多次提及。
您可以更轻松地使用画布进行操作,如果您想保存它,您只需通过邮寄将原始画布数据发送到服务器? http://www.nihilogic.dk/labs/canvas2image/
但是如果你想使用这个插件,我建议你看看你服务器的 php 配置。许多服务器仍然只支持 jpeg 和 gif 作为其默认 php 配置的一部分。如果你想检查这个,请创建一个包含以下代码的 php 文件:
phpinfo();
?>
然后上传并在您的服务器上查看。您应该在页面上查找“libpng”: http ://www.php.net/manual/en/image.requirements.php