473,387 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1994
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: rmn | last post by:
Hi, I'm looking for the translation betwen the color spaces, but I must be mistaken with the methods to use, losing the values. Please, I need a little help of a "coloured guru"....
0
by: Paul Hamlington | last post by:
Hello, I've been programming in ASP for a little while now and quite an advanced user, but I have come across an unusual problem in which I need assistance. I have built my own image upload,...
1
by: John Thompson | last post by:
We're sooo close. When we load the page to upload the image, all of the prms go through except the binary image data. Using SQL server with the data type set to "image". Please help! Thanks-...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
2
by: Tim::.. | last post by:
Hi I'm trying to create a little application that shows an image of a user when you mouseover there details in a datagrid. The datagrid is populated from an Active Directory Database and I...
0
by: Tim::.. | last post by:
I have a datagrid that displays a list of contacts on our intranet site using the ActiveDirectory as it's main Data Source. I want to be able to show an image of each employee using a popup layer...
35
by: Stan Sainte-Rose | last post by:
Hi, What is the better way to save image into a database ? Just save the path into a field or save the image itself ? I have 20 000 images (~ 10/12 Ko per image ) to save. Stan
5
by: massimoal | last post by:
Hi all, I need to convert a tif image, grabbed by a pixelink industrial camera, to a text file (1024x768 elements) but I really don't know how. Surfing the net I found that there are a lot of...
4
by: Muddasir | last post by:
Hi.. i am having a strange problem.......the problem is i am trying to upload a file and to store it in db....when the file got stored in db...it got converted into black and white image and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.