关于在PHP中使用GD来调整图像大小/调整大小的问题 [英] Question on using GD in PHP to size/resize images
问题描述
Hello PHP小组,
我正在使用一些PHP代码来检查图像的大小,然后
调整大小或确定图像的新维度。 GD看起来很慢。
制作7
jpeg图像的尺寸大约需要5秒钟(正负)。
我有一个700mhz的处理器(Pentium III,记得那些??)!几乎
一美元的内存。
这是GD的方式???这是我使用的dode的片段:我将
图像从数组传递给此函数:
函数imageDimensions($ img){
//获取大小从上面的文件创建原始图像
$ orig = imagecreatefromjpeg($ img);
如果($ orig){
//获取高度和宽度
$ orig_y = imagesy($ orig);
$ pic_size [0] = $ orig_x; //宽度
$ pic_size [1] = $ orig_y; //高度
如果($ orig_x 799){
$ image_x = 800;
}其他{
$ image_x = $ orig_x;
}
// $ thumb_x = $ _REQUEST [''thumb_x''];
$ image_y = round(($ orig_y * $ image_x)/ $ orig_x);
// $ thumb_y = round(($ orig_y * $ thumb_x )/ $ orig_x);
$ pic_size [2] = $ image_y;
$ pic_size [3] = $ image_x;
返回$ pic_size;
// echo(" Image width:"。$ orig_x。"。图片高度:" ;. $ orig_y);
}否则{
echo''没有形象!';
}
}
我对改进我的代码的任何建议持开放态度。事实如此!
感谢好团队,
eholz1
Hello PHP group,
I am using some php code to check the size of images, and then
resize or determine new dimension for the image. GD seems quite slow.
It takes about 5 seconds (plus or minus) to calulate dimension for 7
jpeg images.
I have a 700mhz processor (Pentium III, remember those??)! with almost
a gb of memory.
Is that the way GD is??? Here is a snippet of the dode I use: I pass
the image from an array to this function:
function imageDimensions ($img) {
//get size create an original image from file above
$orig = imagecreatefromjpeg($img);
if ($orig) {
//get height and width
$orig_x = imagesx($orig);
$orig_y = imagesy($orig);
$pic_size[0] = $orig_x; //width
$pic_size[1] = $orig_y; //height
if ($orig_x 799) {
$image_x = 800;
}else{
$image_x = $orig_x;
}
// $thumb_x = $_REQUEST[''thumb_x''];
$image_y = round(($orig_y * $image_x) / $orig_x);
// $thumb_y = round(($orig_y * $thumb_x) / $orig_x);
$pic_size[2] = $image_y;
$pic_size[3] = $image_x;
return $pic_size;
//echo("Image width: " . $orig_x . ". Image height: " . $orig_y);
} else {
echo ''No Image!'';
}
}
I am open to any suggestions on improving my "code" as it were!
Thanks for a good group,
eholz1
推荐答案
img){
//获取大小从上面的文件创建原始图像
img) {
//get size create an original image from file above
orig = imagecreatefromjpeg(
orig = imagecreatefromjpeg(
img);
if(
img);
if (
这篇关于关于在PHP中使用GD来调整图像大小/调整大小的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!