Imagecrop而不保存图像

Pat*_*eck 5 php crop

我有一堆产品预览图像,但它们的尺寸不同.

所以我想知道,是否有可能在旅途中裁剪图像而不保存它?

这两个链接应该显示我的意思:

http://xn--nstvedhandel-6cb.dk/alpha_1/?side=vis_annonce&id=12

http://xn--nstvedhandel-6cb.dk/alpha_1/?side=vis_annonce&id=13

RTB*_*RTB 5

是的,我可以这样做:

//Your Image
$imgSrc = "image.jpg";
list($width, $height) = getimagesize($imgSrc);
$myImage = imagecreatefromjpeg($imgSrc);

// calculating the part of the image thumbnail
if ($width > $height)
{
    $y = 0;
    $x = ($width - $height) / 2;
    $smallestSide = $height;
 } 
 else
 {
    $x = 0;
    $y = ($height - $width) / 2;
    $smallestSide = $width;
 }

 // copying the part into thumbnail
 $thumbSize = 100;
 $thumb = imagecreatetruecolor($thumbSize, $thumbSize);
 imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);

 //final output
 header('Content-type: image/jpeg');
 imagejpeg($thumb);
Run Code Online (Sandbox Code Playgroud)

这不是一个非常轻微的操作,像其他人一样,我也建议你在创建它到文件系统后保存缩略图.

你可能想看看PHP的GD库.