不保存图像的图像裁剪 [英] Imagecrop without saving the image
本文介绍了不保存图像的图像裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一堆产品预览图片,但它们不是相同的尺寸。
I have a bunch of product preview images, but they are not the same dimensions.
所以我想知道,是否可以在不保存的情况下裁剪图像?
So i wonder, is it possible to crop an image on the go, without saving it?
这两个链接应该显示我的意思:
These two links should show what i mean:
http ://xn--nstvedhandel-6cb.dk/alpha_1/?side = vis_annonce& id = 12
http://xn--nstvedhandel-6cb.dk/alpha_1/?side=vis_annonce&id=13
推荐答案
是的,这是我的做法:
//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);
这不是非常轻巧的操作,就像其他操作一样,我也建议您在创建后保存缩略图
This is not a verry light operation, like the others i also reccomend you to save the thumbnail after creating it to your file system.
这篇关于不保存图像的图像裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文