473,799 Members | 3,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2009
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
imagecreatefrom jpeg
imagecreatetrue color
imagecoloralloc ate
imagefill
imagecopyresamp led
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***@glassgian t.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.ed u> 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.ed u> 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
2707
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". ----------------------------------------------------- import java.awt.*; import java.awt.image.ColorModel; import java.awt.color.ColorSpace; .... ....
0
2385
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, I have two versions of the binary to string conversion one fast, one slow because some servers use chillisoft and therefore the append function in not accessible for a disconnected recordset.
1
2513
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- John
7
3402
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
2859
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 presume the best way to create the popup is by using a layer with javascript hide and show... I intend to use a database to store the pictures in and the use the users full name to build a relationship between the database with the images and the...
0
1102
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 but am not sure how I match the Active Directory Data to the correct image stored in an SQL database. I plan on using the users fullname or email address as an identifier to match up the image with the correct user but really don't know how to...
35
2676
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
3032
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 methods to write a tiff image but how can I understand which is the one used in mine? Can you suggest me some example of code I can use to read the image?
4
1801
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 the stored in db with the same name("b"appended in the begining of the filename). now the problem is that...the following script only converts three images which i was using through out the testing phase......now it uploads only those three images...
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10252
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.