这个脚本可以帮助我裁剪和保存图像。每次我保存一个图像它保存有crop.jpg ..我可以保存在一个不同的名称?我有一个输入字段的图像名称..“$ _POST ['imgname']”我如何使用此图像名称的裁剪图像?以独特名称保存裁剪图像?
<?php
$canvasImg = $_POST['img'];
$data = base64_decode($canvasImg);
$File = "captured.jpg";
$Handle = fopen($File, 'w');
fwrite($Handle, $data);
fclose($Handle);
$src_image = imagecreatefrompng($File);
$width = imagesx($src_image);
$height = imagesy($src_image);
$dst_x = 0;
$dst_y = 0;
$src_x = $width*0.350; // Crop Start X
$src_y = $height*0.165; // Crop Srart Y
$dst_w = $width*0.294; // Thumb width
$dst_h = $height*0.470; // Thumb height
$src_w = $dst_w; // $src_x + $dst_w
$src_h = $dst_h; // $src_y + $dst_h
$image = imagecreatetruecolor($dst_w, $dst_h);
imagealphablending($image, false);
$col=imagecolorallocatealpha($image,255,255,255,127);
imagefilledrectangle($image,0,0,$dst_w, $dst_h,$col);
imagealphablending($image,true);
imagecopyresampled($image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
imagealphablending($image,true);
imagealphablending($image,false);
imagesavealpha($image,true);
imagepng($image, "images/crop.jpeg");
imagedestroy($image);
?>
'imagepng($ image,“images/crop.jpeg”);'改变这个。提示:不要总是依赖复制粘贴。 –
您可以将其重命名为时间戳并保存。 – krishna
嗨..改成什么? n sry for copy-paste :) – gumireddy