<?php
$src_path = 'ha.jpg';
$src = imagecreatefromstring(file_get_contents($src_path));
$x = 100;
$y = 12;
$width = 200;
$height = 200;
$final_width = 100;
$final_height = round($final_width * $height / $width);
$new_image = imagecreatetruecolor($final_width, $final_height);
imagecopyresampled($new_image, $src, 0, 0, $x, $y, $final_width, $final_height, $width, $height);
header('Content-Type: image/jpeg');
imagejpeg($new_image);
imagedestroy($src);
imagedestroy($new_image);
ecshop后台处理图片
$src_img = ROOT_PATH . $goods_img;
include_once(ROOT_PATH . 'includes/cls_json.php');
$json = new JSON;
$avatar_data = $_POST['avatar_data'];
$avatar = $json->decode($avatar_data, true);
$dst_w = trim($avatar['width']);
$dst_h = trim($avatar['height']);
$xx = trim($avatar['x']);
$yy = trim($avatar['y']);
$rotate = trim(-$avatar['rotate']);
list($src_w, $src_h) = getimagesize($src_img);
$source = imagecreatefromjpeg($src_img);
$rotate = imagerotate($source, $rotate, 0);
$croped = imagecreatetruecolor($dst_w, $dst_w);
imagecopy($croped, $rotate, 0, 0, $xx, $yy, $dst_w, $dst_h);
$scale = $dst_w / $src_w;
$final_w = $dst_w * $scale;
$final_h = $dst_w * $scale;
$target = imagecreatetruecolor($final_w, $final_h);
imagecopyresampled($target, $croped, 0, 0, 0, 0, $final_w, $final_h, $dst_w, $dst_h);
$timestamp = time();
imagejpeg($target, $src_img);
imagedestroy($croped);