我有软件,它通过 POST 将图像“发送”到服务器上的 php-script。我必须裁剪每一张照片。所以有 2 个步骤:使用 Curl 和 Crop 获取它。但裁剪部分不起作用(卷曲部分效果很好并保存图像)。
`
// 1. GET IMAGES VIA POST
$imgpath = $_POST['img_url'];
$dirname = $_POST['img_folder'];
$imgid = $_POST['imgid'];
$ch = curl_init($imgpath);
$fn = ($imgid.substr($imgpath,strrpos($imgpath,'/')+1,strlen($imgpath)));
$fn = str_replace('?', '_', $fn);
$fn = str_replace('=', '_', $fn);
if (is_dir($dirname)==FALSE) mkdir($dirname);
$fp = fopen($dirname.'/'.$fn, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
// 2. CROP IMAGE
$in_filename = $_POST['img_url'];
list($width, $height) = getimagesize($in_filename);
$offset_x = 0;
$offset_y = 0;
$new_height = $height - 40;
$new_width = $width;
$out_filename = $in_filename . '_crop';
$image = imagecreatefromjpeg($in_filename);
$new_image = imagecreatetruecolor($new_width, $new_height);
imagecopy($new_image, $image, 0, 0, $offset_x, $offset_y, $width, $height);
header('Content-Type: image/jpeg');
imagejpeg($new_image, $out_filename);
imagedestroy($new_image);
echo($dirname.'/'.$fn);`