473,383 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,383 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 1993
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.