470,867 Members | 1,805 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,867 developers. It's quick & easy.

Guru: Image conversion

Hi, suppose I'd like to convert my JPG images(in a directory) into a lower
resolution and uniform size(while maintaining its aspect ratio), I would I
do that in PHP?

I've seen code with PHP/GD but can't yet figure out how to do it and apply
the result into a new name. Thanks
Jul 17 '05 #1
7 1826
On Tue, 03 Feb 2004 08:51:18 -0500, Useko Netsumi wrote:
Hi, suppose I'd like to convert my JPG images(in a directory) into a lower
resolution and uniform size(while maintaining its aspect ratio), I would I
do that in PHP?

I've seen code with PHP/GD but can't yet figure out how to do it and apply
the result into a new name. Thanks


You want to do yhis on the command line? If yes, then use ImageMagick or
NetPBM.

You want to do it in a script? A PHP script running on a Webserver?

If yes, say so.

Do not, I repeat, do *not* write a script to process one image on the
(Linux) command line using PHP/GD when NetPBM and/or ImageMagick would be
a far better,easier, and faster way to do it.

later, hoss....

--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Website | http://www.wse.jhu.edu/newtnotes/

Jul 17 '05 #2
Useko Netsumi wrote:

Hi, suppose I'd like to convert my JPG images(in a directory) into a lower
resolution and uniform size(while maintaining its aspect ratio), I would I
do that in PHP?

I've seen code with PHP/GD but can't yet figure out how to do it and apply
the result into a new name. Thanks


You could try hotscripts.com. Search the PHP section for "gallery" or
"thumbnail". You might not find what you're looking for exactly. But you're
more likely to get help here if you have a specific programming problem.

If you wanted to write one from scratch you could read up on PHP's image
functions here:

http://ca.php.net/manual/en/ref.image.php

The basic approach would be to read a directory for images. For each image,
create an image of the size you want, say with a black or white background, and
copy the original into the new one, keeping the same aspect ratio with basic
math. This would mean you'd have bars on the top and bottom or left and right,
depending on the image's aspect ratio. Or you could set your code to crop the
image to maintain aspect ratio. Then you'd save the image to a new directory
with the same or similar filename.

Functions you could use:

readdir
preg_match
imagecreatefromjpeg
imagecreatetruecolor
imagecolorallocate
imagefill
imagecopyresampled
imagejpeg

You wouldn't have to use all these, and you'd probably use a few more, but this
would get you started.

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #3

----- Original Message -----
From: "Useko Netsumi" <us*****************@earthlink.net>
Hi, suppose I'd like to convert my JPG images(in a directory) into a lower
resolution and uniform size(while maintaining its aspect ratio), I would I
do that in PHP?

I've seen code with PHP/GD but can't yet figure out how to do it and apply
the result into a new name. Thanks


1) Create source image object from the file.
2) Create destination image object with right size.
3) Copyresampled source image to destination image
4) Save destination image object into a new file.

Really, check the manual from image functions, its all there.

perttu, finland
Jul 17 '05 #4
see gzImage, there is code in there that does it.

http://www-3.gzentools.com/gzimg.php

--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Useko Netsumi" <us*****************@earthlink.net> wrote in message
news:bv************@ID-205437.news.uni-berlin.de...
Hi, suppose I'd like to convert my JPG images(in a directory) into a lower
resolution and uniform size(while maintaining its aspect ratio), I would I
do that in PHP?

I've seen code with PHP/GD but can't yet figure out how to do it and apply
the result into a new name. Thanks

Jul 17 '05 #5
Ideally, I'd love to do it on the fly with PHP script. Thanks

"Jeffrey Silverman" <je*****@jhu.edu> wrote in message
news:pa****************************@jhu.edu...
On Tue, 03 Feb 2004 08:51:18 -0500, Useko Netsumi wrote:
Hi, suppose I'd like to convert my JPG images(in a directory) into a lower resolution and uniform size(while maintaining its aspect ratio), I would I do that in PHP?

I've seen code with PHP/GD but can't yet figure out how to do it and apply the result into a new name. Thanks


You want to do yhis on the command line? If yes, then use ImageMagick or
NetPBM.

You want to do it in a script? A PHP script running on a Webserver?

If yes, say so.

Do not, I repeat, do *not* write a script to process one image on the
(Linux) command line using PHP/GD when NetPBM and/or ImageMagick would be
a far better,easier, and faster way to do it.

later, hoss....

--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Website | http://www.wse.jhu.edu/newtnotes/

Jul 17 '05 #6
On Tue, 03 Feb 2004 18:55:08 -0500, Useko Netsumi wrote:
Ideally, I'd love to do it on the fly with PHP script. Thanks


Okay... well, that's possible.

But...
I'm not going to write the script for you.

Try writing the script. If you get stuck, come back to the newsgroups
and post a specific question about your problem, post error messages and
code, and then we'll see if we can help.
later...

--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Website | http://www.wse.jhu.edu/newtnotes/

Jul 17 '05 #7
already written:
http://www-4.gzentools.com/gzimg.php

--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Useko Netsumi" <us*****************@earthlink.net> wrote in message
news:bv************@ID-205437.news.uni-berlin.de...
Ideally, I'd love to do it on the fly with PHP script. Thanks

"Jeffrey Silverman" <je*****@jhu.edu> wrote in message
news:pa****************************@jhu.edu...
On Tue, 03 Feb 2004 08:51:18 -0500, Useko Netsumi wrote:
Hi, suppose I'd like to convert my JPG images(in a directory) into a lower resolution and uniform size(while maintaining its aspect ratio), I
would
I do that in PHP?

I've seen code with PHP/GD but can't yet figure out how to do it and apply the result into a new name. Thanks


You want to do yhis on the command line? If yes, then use ImageMagick or
NetPBM.

You want to do it in a script? A PHP script running on a Webserver?

If yes, say so.

Do not, I repeat, do *not* write a script to process one image on the
(Linux) command line using PHP/GD when NetPBM and/or ImageMagick would be a far better,easier, and faster way to do it.

later, hoss....

--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Website | http://www.wse.jhu.edu/newtnotes/


Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Paul Hamlington | last post: by
1 post views Thread by John Thompson | last post: by
7 posts views Thread by Scott Schluer | last post: by
2 posts views Thread by Tim::.. | last post: by
reply views Thread by Tim::.. | last post: by
35 posts views Thread by Stan Sainte-Rose | last post: by
5 posts views Thread by massimoal | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.