此代码用于将裁剪的图像保存在同一位置。
以下是上述代码:
$targ_w = 396; // set the width of the new image
$targ_h =400; //set the height og the new image
$src = $_POST['img_src']; //get the image source
$img_r = imagecreatefromjpeg($src); //open the image
$dst_r = imagecreatetruecolor( $targ_w,$targ_h); //create a new image
imagecopyresampled($dst_r,$img_r,0,0,$_POST['datax'],$_POST['datay'],$targ_w,$targ_h,$_POST['datawidth'],$_POST['dataheight']); // create the new image with the specified width and height from jcrop
unlink($src); //delete the old image
imagejpeg($dst_r,$src,100); // save the new image
imagedestroy($img_r);
答案 0 :(得分:0)
请在下面的脚本中尝试裁剪图像。
<?php
if (isset($_FILES["file"])) {
$tmpFile = $_FILES["file"]["tmp_name"];
$fileName = 'file name';
list($width, $height) = getimagesize($tmpFile);
// check if the file is really an image
if ($width == null && $height == null) {
header("Location: index.php");
return;
}
// resize if necessary
if ($width >= 400 && $height >= 400) {
$image = new Imagick($tmpFile);
$image->thumbnailImage(400, 400);
$image->writeImage($fileName);
}
else {
move_uploaded_file($tmpFile, $fileName);
}
}
这会有所帮助......