473,503 Members | 756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question on using GD in PHP to size/resize images

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

Jan 6 '07 #1
11 2330
If you're trying to make thumbnails, you should actually resample the
images, otherwise, your web page will take a while to load, even if you
change the dimensions in the image tag.

See: http://php.net/manual/en/function.im...yresampled.php

On Jan 5, 10:01 pm, "eholz1" <ewh...@gmail.comwrote:
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
Jan 6 '07 #2
Message-ID: <11**********************@v33g2000cwv.googlegroups .comfrom
eholz1 contained the following:
>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.
You don't need GD to get image sizes
http://uk2.php.net/manual/en/function.getimagesize.php

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jan 6 '07 #3
Geoff Berrow wrote:
Message-ID: <11**********************@v33g2000cwv.googlegroups .comfrom
eholz1 contained the following:

>>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.


You don't need GD to get image sizes
http://uk2.php.net/manual/en/function.getimagesize.php
if you are doing thumbnails you need neither.

<a href='<?php echo $path ?>'>
<img src='<?php echo $imagelist[$i] ?>' width='50' height='50' class='thumb'>

I found this in a php script called imagebrowser.php (a google search should
locate it...)

--
Michael Austin.
Database Consultant
Jan 6 '07 #4
Michael Austin wrote:
Geoff Berrow wrote:
>Message-ID: <11**********************@v33g2000cwv.googlegroups .comfrom
eholz1 contained the following:

>>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.

You don't need GD to get image sizes
http://uk2.php.net/manual/en/function.getimagesize.php

if you are doing thumbnails you need neither.

<a href='<?php echo $path ?>'>
<img src='<?php echo $imagelist[$i] ?>' width='50' height='50'
class='thumb'>

I found this in a php script called imagebrowser.php (a google search
should locate it...)
And this is exactly what yous should NOT do. It causes the entire
(large) image to load, then be resized by the browser.

It is much better to create thumbnails and send an image of the
appropriate size. Depending on the original image size, the size
difference is enormous. For instance, if the original image size is
500x500, your thumbnail may be as much as 99% smaller than the original.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 6 '07 #5
Hello Curtis and the others,

This is exactly what I needed. I am doing some testing with images,
etc. My plan is to read/check a
given image file, and load its name, size, filetype, etc into a
database, and display the image (via a thumbnail link, etc). So the
link to the php stuff is very useful, and all i need at this point is
to get image data, and do not need to process image yet (like make a
thumbnail, resize image to browser size (maybe 900 x 600, etc).

Thanks again,

eholz1,

Curtis wrote:
If you're trying to make thumbnails, you should actually resample the
images, otherwise, your web page will take a while to load, even if you
change the dimensions in the image tag.

See: http://php.net/manual/en/function.im...yresampled.php

On Jan 5, 10:01 pm, "eholz1" <ewh...@gmail.comwrote:
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
Jan 6 '07 #6
Hello Jerry,

I love your posts!!!

Thanks,

ehozl1
Jerry Stuckle wrote:
Michael Austin wrote:
Geoff Berrow wrote:
Message-ID: <11**********************@v33g2000cwv.googlegroups .comfrom
eholz1 contained the following:
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.

You don't need GD to get image sizes
http://uk2.php.net/manual/en/function.getimagesize.php
if you are doing thumbnails you need neither.

<a href='<?php echo $path ?>'>
<img src='<?php echo $imagelist[$i] ?>' width='50' height='50'
class='thumb'>

I found this in a php script called imagebrowser.php (a google search
should locate it...)

And this is exactly what yous should NOT do. It causes the entire
(large) image to load, then be resized by the browser.

It is much better to create thumbnails and send an image of the
appropriate size. Depending on the original image size, the size
difference is enormous. For instance, if the original image size is
500x500, your thumbnail may be as much as 99% smaller than the original.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 6 '07 #7
One last question,

In terms of making thumbnails, resizing images, etc are there any other
programs that work better
(whatever "better" means) than GD??? I have a version of gallery
(menalto opensource program) and it seems to like netpbm, ImageMagik,
etc. are either of these better or faster, etc. Or are they more or
less equal??? My goal is to check size of original image (typically
3000px by 3072 px) and make a thumbnail, and resize the "big" image to
appropriate browser size (a poor man's gallery program).
and when a viewer clicks the thumbnail, display the bigger image via
php in browser.

eholz1

eholz1 wrote:
Hello Jerry,

I love your posts!!!

Thanks,

ehozl1
Jerry Stuckle wrote:
Michael Austin wrote:
Geoff Berrow wrote:
>
>Message-ID: <11**********************@v33g2000cwv.googlegroups .comfrom
>eholz1 contained the following:
>>
>>
>>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.
>>
>>
>>
>You don't need GD to get image sizes
>http://uk2.php.net/manual/en/function.getimagesize.php
>>
>
if you are doing thumbnails you need neither.
>
<a href='<?php echo $path ?>'>
<img src='<?php echo $imagelist[$i] ?>' width='50' height='50'
class='thumb'>
>
I found this in a php script called imagebrowser.php (a google search
should locate it...)
>
And this is exactly what yous should NOT do. It causes the entire
(large) image to load, then be resized by the browser.

It is much better to create thumbnails and send an image of the
appropriate size. Depending on the original image size, the size
difference is enormous. For instance, if the original image size is
500x500, your thumbnail may be as much as 99% smaller than the original.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 6 '07 #8
On 6 Jan 2007 09:18:15 -0800, "eholz1" <ew****@gmail.comwrote:
>In terms of making thumbnails, resizing images, etc are there any other
programs that work better
(whatever "better" means) than GD??? I have a version of gallery
(menalto opensource program) and it seems to like netpbm, ImageMagik,
etc. are either of these better or faster, etc. Or are they more or
less equal??? My goal is to check size of original image (typically
3000px by 3072 px) and make a thumbnail, and resize the "big" image to
appropriate browser size (a poor man's gallery program).
and when a viewer clicks the thumbnail, display the bigger image via
php in browser.
ImageMagick is generally more suited to processing photographic images; GD is
mostly for computer-generated "block" graphics. ImageMagick is also somewhat
faster for image processing (resize etc.) and can give subjectively better
results as there's many options for filters and convolutions.

See also http://groups.google.co.uk/group/com...76e8f1a175b4ed

The downside is that (a) it has to be installed in the first place and (b) you
may need to shell out to the "convert" command, although there are a couple of
PHP APIs that give you direct access to the ImageMagick API.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jan 6 '07 #9
Hello Andy,

Thanks for the info. I do have both netpbm and ImageMagik installed on
my "test" server, so that is ok.
I can convert images, and them move them to my production web site.
Thanks again,

ewholz

(how come all the image stuff seems to come from the UK???, I guess no
one uses it in the US :)
Andy Hassall wrote:
On 6 Jan 2007 09:18:15 -0800, "eholz1" <ew****@gmail.comwrote:
In terms of making thumbnails, resizing images, etc are there any other
programs that work better
(whatever "better" means) than GD??? I have a version of gallery
(menalto opensource program) and it seems to like netpbm, ImageMagik,
etc. are either of these better or faster, etc. Or are they more or
less equal??? My goal is to check size of original image (typically
3000px by 3072 px) and make a thumbnail, and resize the "big" image to
appropriate browser size (a poor man's gallery program).
and when a viewer clicks the thumbnail, display the bigger image via
php in browser.

ImageMagick is generally more suited to processing photographic images; GD is
mostly for computer-generated "block" graphics. ImageMagick is also somewhat
faster for image processing (resize etc.) and can give subjectively better
results as there's many options for filters and convolutions.

See also http://groups.google.co.uk/group/com...76e8f1a175b4ed

The downside is that (a) it has to be installed in the first place and (b) you
may need to shell out to the "convert" command, although there are a couple of
PHP APIs that give you direct access to the ImageMagick API.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jan 6 '07 #10
eholz1 wrote:
One last question,

In terms of making thumbnails, resizing images, etc are there any other
programs that work better
(whatever "better" means) than GD??? I have a version of gallery
(menalto opensource program) and it seems to like netpbm, ImageMagik,
etc. are either of these better or faster, etc. Or are they more or
less equal??? My goal is to check size of original image (typically
3000px by 3072 px) and make a thumbnail, and resize the "big" image to
appropriate browser size (a poor man's gallery program).
and when a viewer clicks the thumbnail, display the bigger image via
php in browser.

eholz1

eholz1 wrote:
>>Hello Jerry,

I love your posts!!!

Thanks,

ehozl1
Jerry Stuckle wrote:
>>>Michael Austin wrote:

Geoff Berrow wrote:
>Message-ID: <11**********************@v33g2000cwv.googlegroups .comfrom
>eholz1 contained the following:
>
>
>
>>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.
>
>
>
>You don't need GD to get image sizes
>http://uk2.php.net/manual/en/function.getimagesize.php
>

if you are doing thumbnails you need neither.

<a href='<?php echo $path ?>'>
<img src='<?php echo $imagelist[$i] ?>' width='50' height='50'
class='thumb'>

I found this in a php script called imagebrowser.php (a google search
should locate it...)
And this is exactly what yous should NOT do. It causes the entire
(large) image to load, then be resized by the browser.

It is much better to create thumbnails and send an image of the
appropriate size. Depending on the original image size, the size
difference is enormous. For instance, if the original image size is
500x500, your thumbnail may be as much as 99% smaller than the original.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

I agree with Andy. ImageMagick is the best way to go, if you can
install it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 6 '07 #11
Message-ID: <11**********************@51g2000cwl.googlegroups. comfrom
eholz1 contained the following:
>
In terms of making thumbnails, resizing images, etc are there any other
programs that work better
(whatever "better" means) than GD??? I have a version of gallery
(menalto opensource program) and it seems to like netpbm, ImageMagik,
etc. are either of these better or faster, etc. Or are they more or
less equal??? My goal is to check size of original image (typically
3000px by 3072 px) and make a thumbnail, and resize the "big" image to
appropriate browser size (a poor man's gallery program).
and when a viewer clicks the thumbnail, display the bigger image via
php in browser.
Done that :-)
www.walkingoutdoors.co.uk/Geoff/gallery/

Code:
http://www.walkingoutdoors.co.uk/Geo...ry/gallery.zip
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jan 7 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2436
by: DH | last post by:
I have a "file upload form" that works OK, but I have been unsuccessful in my attempt to also resize the uploaded .JPG (if it is too wide), over-writing the original .JPG, and then create and save...
2
3000
by: Fredo Vincentis | last post by:
Is there any possibility to resize images using ASP? I provided one of my clients with a Content Management System using SAFileup and although I told him to resize images to a reasonable size...
5
35069
by: Chris Stromberger | last post by:
I have a div with a width of 40em (is em cool to use for width?). The situation below applies even if width is auto or 80% or something. Inside the div I am displaying some code with <pre> tags. ...
1
1663
by: jdapro | last post by:
Hi - thanks for reading this out there! I'll be quick about it: I've got this row of images (in the end there will be more rows of pics as well). When a user clicks on the image, I want a new...
3
13112
by: Jefferis NoSpamme | last post by:
Hello all, I'm trying to limit the file size to 1 meg on upload of image files and I am trying a script from javascript internet, but it is giving me errors on IE ² is null or not an object ³...
3
4480
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need ...
2
2486
by: Tim Arnold | last post by:
Hi, I'm using the Image module to resize PNG images from 300 to 100dpi for use in HTML pages, but I'm losing some vertical and horizontal lines in the images (usually images of x-y plots). ...
11
5795
by: shapper | last post by:
Hello, I am displaying an image on a few pages. The image size is 50 px height and 50 px width. In some pages I need the image to be 30x30 px in others 40x40 px and in others 50x50px. Can I...
8
2253
tharden3
by: tharden3 | last post by:
Hey Bytes, The website I'm working on is coming along just fine, and I'd like to thank all of you PHP folks who have been helping me out. I'm almost done with the coding! I'm trying to get the...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.