Link to home
Start Free TrialLog in
Avatar of Gary
GaryFlag for Ireland

asked on

jpeg optimize and make progressive

Anyone got a handy script that will run through an image folder optimizing the images and converting them to progressive?
Using GD
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

This does the 'progressive' part: http://www.php.net/manual/en/function.imageinterlace.php  What are you going to 'optimize' them for?
I've never tried the "interlace" idea, but I know that when you use ImageJPEG() you can set the $quality option to reduce the file size.

Internet connections are very fast today.  But here is how you might do it.

1. Scandir() to collect the filenames
2. Iterator like foreach() to look for image files
3. ImageCreateXXX() to choose the images
4. ImageInterlace() to make them progressive
5. ImageJPEG() to store the interlaced image files

I think I would use a different output image directory and then you could look at the files side-by-side to compare file sizes and visual quality.
Avatar of Gary

ASKER

I'm just being lazy, I do have progressive script somewhere - cannot find it at the mo.
Basically looking for a script that will go thru a folder with about 4000 images, optimize their size - quite a few (well most of them) are not optimized i.e. I could halve if not more their size - and save them as progressive jpg's at the same time.
Running from a console so timeout's is not a problem.
Hi GaryC123, this web image file size "Make Smaller" PROBLEM is older than the internet web and older than the very idea of digital images and file size, so you are asking a common question that has been asked thousands of times and partially  solved for jpg images in thousands of ways, in PHP and many other setups! ! You need to be more informed about JPG images and their levels of file compression, , , especially the trade offs necessary for file size reduction for any digital image.
I just did a web search for "php jpg image optimizer" and got  14,700,000 results!

Maybe you could tell us about why you think you need more image compression, and some of the factors you see in the 4000 images you have, , to make you think about mass "optimize and make progressive" for them.   As it is, you do not give enough information to give you an answer that narrows down the many options available to us for you about the  half the size thing.
Avatar of Gary

ASKER

None of the images are saved for the web - they need optimizing - simple.
Quality taken down to about 80%

Thought someone might have a ready made script handy to save me time writing it.
Maybe I can tinker around with this.  Please clarify... Do you want to reduce the image size at all, or keep the same pixel dimensions?  And are you willing to accept the fact that progressive JPGs may be larger than non-progressive JPGs of equal or even lower resolution?
Avatar of Gary

ASKER

Same size - no resizing in dimensions.
A lot of the images are around 100kb and could be optimized to around 70-80kb without any loss in quality.
Yes I know the progressive may increase the size (a few kb) but that's why I want to optimize as well before applying the progressive.
Avatar of Gary

ASKER

Attached is an example image 187kb, saved optimized and progressive takes it down to 33kb (using Photoshop).
I could setup a batch script in PS but then I would need to reupload all the images again
e22669.jpg
Avatar of Gary

ASKER

I actually reduced that image to 30%
The image I attached was the optimized one, reattaching the original.
You will see there is no discernible difference in quality but it is a sixth of the size.
e22669--2-.jpg
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gary

ASKER

Yeah that seems to work great - thanks.
J' Welcome!  Thanks for the points, ~Ray