Let me explain what I am trying to do, I am building a command line tool with PHP that uses these programs to optimize images for the web…
imagemagick to determine file type and convert non-animated gif’s to png
gifsicle to optimize Animated Gif images
jpegtran to optimize jpg images
pngcrush to optimize png image
pngquant to optimize png images to png8 format
pngout to optimize png images to png8 format
This is a pretty heavy process to be running, luckily it is done very infrequently but I would still like to optimize as much as I can.
Right now to process around 12 images takes roughly 76 seconds. So you can see it is a slow process, imagine 100 images.
I would really like to somehow, mark an image as optimized somehow, so when I am loading a batch of images, the first thing it does is run through ImageMagick to get the exact file type, would be nice if I could somehow embed a message that says this image is already optimized as much as it can be, and then when I am reading images in, if it detects a message it will know to not waste valuable time running that particular image through all the other programs, if this is possible, it could greatly increase speed.
Please help me, I am not used to working with images like this, is this possible even, if it is what is it called and how could I achieve it?
Thanks for any help
If you were to include a flag in the image itself then that would be served to the clients. It would add to the filesize of your images thus negating some of your optimisation.
Suggestions
Keep a reference of the status
Keep a catalog in a file in the same directory – much like the Windows
Thumbs.dbfile.Another option would be to keep the record in a database or datastore such as Redis or Memcached.
Move after processing
You could move the files to a different directory once they are processed (as @Jordan mentions).
Change the filename to indicate it is processed
Another option would be to append an extra “extension” onto the file name for example:
Embedding data in images
Steganography
Usually this is used for attempting to hide covert data in an image and it is called Steganography. It is not really suited to this use case however.
EXIF data
You could write it into the EXIF data of an image, but this would be JPEG and TIFF only as far as I am aware. There is a PHP library available called PEL for writing and reading EXIF data.