Is there a way to set some data in an image

Let me explain what I'm trying to do, I am creating a command line tool with PHP that uses these programs to optimize images for the web ...

imagemagick to determine file type and convert unanimated gif to png
gifsicle to optimize animated gifsicle
jpegtran for optimizing jpg images
pngcrush for image optimization png
pngquant to optimize pngquant images in png8 format
pngout to optimize pngout images in png8 format

This is a rather difficult process to start, fortunately, this is done very rarely, but I still would like to optimize as much as I can.

Now it takes about 76 seconds to process about 12 images. So you can see that this is a slow process, imagine 100 images.

I would really like to somehow mark the image as somehow optimized, so when I download the image package, the first thing it does is run through ImageMagick to get the exact file type, it would be nice if I could somehow insert a message stating that this image is already optimized as much as it can be, and then when I read the image, if it detects a message that it will know, so as not to waste precious time doing this particular image through all THER program, if possible, it can significantly increase the speed.

Please help me, I'm not used to working with such images, is it possible, even if this is what is called, and how can I achieve it?

Thanks for any help

+4
source share
2 answers

If you must include a flag in the image, then this will be served to customers. This would add to the size of your images, thereby negating some of your optimizations.

suggestions

Save Status Link

Store the directory in a file in the same directory as the Windows Thumbs.db file.

Another option is to save the record in a database or data warehouse, such as Redis or Memcached .

Move after processing

You can move files to another directory after processing them (as @Jordan mentions).

Change the file name to indicate that it has been processed

Another option is to add an additional “extension” to the file name, for example:

 my_image.processed.jpg 

Embedding data in images

steganography

This is usually used to hide hidden data in an image and is called Steganography . However, this is not suitable for this use case.

EXIF Data

You can write it to EXIF ​​image data, but that would only be JPEG and TIFF as far as I know. There is an accessible PHP library called PEL for writing and reading EXIF ​​data.

+2
source

You can use the Comment field to mark your image as already optimized, for example:

 convert x.jpg -set comment "Optimised" x.jpg 

Then, when you process, you can extract it like this:

 identify -format "%c" x.jpg Optimised 
0
source

Source: https://habr.com/ru/post/1390599/


All Articles