我使用了一个名为"jcrop“的插件,它非常不错,你可以在这里看到它:
http://howhack.com/crop/demos/crop2.php
问题是这个插件不支持透明背景的png。
在javascript / jQuery中是否有类似的脚本/插件支持透明背景的png?
我需要这个长宽比为16:9的矩形,最终的图像总是640x360,这就是为什么我尝试使用这个"jcrop“。
发布于 2011-09-09 23:25:11
我假设这个插件通过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() here时,有几次涉及到这一点。
发布于 2011-09-09 23:21:54
使用canvas可以轻松得多,如果您想保存它,只需通过post - http://www.nihilogic.dk/labs/canvas2image/将原始canvas数据发送到服务器
但是如果你想使用这个插件,我建议你看看你的服务器的php配置。许多服务器仍然只支持jpeg和gif作为其默认php配置的一部分。如果你想检查这一点,创建一个php文件,其中包含以下代码:
phpinfo();
?>
然后上传并在您的服务器上查看。您应该在页面上查找"libpng“:http://www.php.net/manual/en/image.requirements.php
https://stackoverflow.com/questions/7368346
复制相似问题