0

Does anyone know of an linux based script/program which will run continuously on the server and monitor a folder (with sub folders preferably) image files and optimise them, ala smash.it pngout, jpegtrans etc. Preferably all those tools.

I know there are lot of linux apps which will call upon these tools but I want one that will monitor a folder containing our website images and optimise new images (ignoring the images its already optimised previously) - on first run it should do everything, but after that it should know what its already processed.

Does such a tool exist?

realdannys
  • 1,383
  • 1
  • 12
  • 18

1 Answers1

1

if you can use a hook into inotify, use that. for example, let incron monitor specific directories, to which files are added or modified. if so, incron passes control to a program of your choice. convert, from imagemagick, can be useful for reducing image filesizes. incron can pass name of altered/added files to your command or script, allowing it to work specifically on mutations, by using these variables as parameters to your commands:

 $@   watched filesystem path
 $#   event-related file name
 $%   event flags (textually)
 $&   event flags (numerically)
Deleted User
  • 2,551
  • 1
  • 11
  • 18
  • That sounds like just the ticket Bushmills, thanks, i'll look at incron and i'll have a play with image apps, see which one complains the most source tools. – realdannys Jun 20 '14 at 15:26
  • be aware that some time ago there was a small, but annoying bug: when adding lines to incrontab, the fields either must, or may not, be seperated by tabs instead of spaces. I forgot which way around. – Deleted User Jun 20 '14 at 15:27
  • Hi Bushmills. I can see with incron how I can easily get it to monitor for new files in the directory and them get it to run a terminal command when it seems them. However this would just trigger the terminal command, is there a way to also send the information of the new files to the image compression program so its just acting on those files and not the entire directory each time? – realdannys Jun 21 '14 at 20:15
  • yes, sure. I have updated the answer with variable names you can use . Those are substituted when command is executed, against the event associated values – Deleted User Jun 21 '14 at 22:14
  • Ok, I think from what I can find it works with symbols like $N, presumably if 5 files are added, it will send the command 5 times for each file? – realdannys Jun 22 '14 at 10:52
  • As files aren't changed/modified at the exactly the same time, each change represents its own event. You may want to write the convert script such that the target file, in case it is written to a monitored directory and therefore causes another event, isn't converted again. Writing it to an unmonitored directory does away with the need of special attention there. incrontab action could also just write to a journal, from which the actual conversion pulls information. – Deleted User Jun 22 '14 at 11:02