Forum Moderators: coopster

Message Too Old, No Replies

scaling images using PHP

         

scorpion

2:18 pm on Apr 25, 2003 (gmt 0)

10+ Year Member



Does the GDS library of PHP suppor the rescaling of JPG images? If not, is there a way to rescale a JPG image? Thanks.

TheWebographer

2:39 pm on Apr 25, 2003 (gmt 0)

10+ Year Member



Well the simplest way, off the top of my head, is to just dynamically specify the height and width of the image. for example:

img src=xyz.jpg width=<? echo $w/4;?> height=<? echo $h/4?>

Where you can specify and height and width, perhaps as a fraction of the real image for a thumbnail for example.

scorpion

2:49 pm on Apr 25, 2003 (gmt 0)

10+ Year Member



Ok, i don't mean like what you can do with HTML, constricting the height and width of a large image - it still looks bad (jagged edges, etc..) By scale I mean kind of like what you can do with Photoshop, so the image actually looks respectable at the smaller size..is that what that routine can do?

Birdman

2:54 pm on Apr 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See PHP Bag 'O Tricks II [webmasterworld.com]. You can probably extract the code you need from from there.

TheWebographer

2:54 pm on Apr 25, 2003 (gmt 0)

10+ Year Member



Generally you can make an image smaller without it looking too bad just by changing its height and width in the img tag. However, making an image larger in this way does not always produce good results.

limbo

3:09 pm on Apr 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



scorpion

I am not sure if there is a method to do this but I thought I would add that resizing images using scripts will most likely achieve the result but will not manage to compress/optimise the image. Thus the smaller image will have the download time of the original.

I would go the well trodden route and resize and optimise the image using an image editor like P'shop or Fireworks.

If you have many images that need resizing to the a same dimensions I.e. for making a batch of thumbnails from a series of photo's there are macro's you can run using P'shop. But I have only heard this in theory.

Dunno if that is helpful at all

Ta

Limbo

senior mcinvale

3:45 pm on Apr 25, 2003 (gmt 0)

10+ Year Member



it all depends on what is installed on your server my friend.

i use netPBM with great results on several sites. it handles many image types and it easy to work with from a command line.

find out what image packages your server has installed and perhaps i can help you.

scorpion

4:50 pm on Apr 25, 2003 (gmt 0)

10+ Year Member



well, I have an image about 300x500 and has to be shown at roughly 50x75, but dynamically...the img tag method is fine but it leaves the image looking pretty ugly/jagged edges, etc.. perhaps the key is to find the optimium ratio...

Timotheos

4:58 pm on Apr 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's two articles on sitepoint.com about this subject. One uses the GD libraries www.sitepoint.com/article/937
and the other figures how to optimize with the img tag
www.sitepoint.com/article/1058

Interesting stuff. Hope this helps.

Tim

[edited by: jatar_k at 4:38 am (utc) on April 30, 2003]
[edit reason] delinked [/edit]

senior mcinvale

4:59 pm on Apr 25, 2003 (gmt 0)

10+ Year Member



your still loading the 300x500 image though...

scorpion

5:16 pm on Apr 25, 2003 (gmt 0)

10+ Year Member



Yeah, I guess what I'm looking for is a php function that will resize the "resolution" of the image, not just the size...actually change the pixel count and also resample it...

senior mcinvale

5:49 pm on Apr 25, 2003 (gmt 0)

10+ Year Member



oops, read that wrong.

check out these types of functions: [php.net...]

Timotheos

7:48 pm on Apr 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm... looks like your on to something

There's lots of code snippets under here too.
[php.net...]