jpegtran optimize without changing filename

后端 未结 6 2077
囚心锁ツ
囚心锁ツ 2021-02-05 06:42

I need to optimize some images, but not change their name.

jpegtran -copy none -optimize image.jpg > image.jpg 

However, this seems to crea

6条回答
  •  天命终不由人
    2021-02-05 07:36

    Without sponge, another alternative with lower HDD or SSD writing access is to use the /dev/shm to save the temporary file and then overwrite it locally right away.

    jpegtran -copy none -optimize image.jpg > /dev/shm/tmp.jpg &&  cat /dev/shm/tmp.jpg > ./image.jpg
    

    The concept can be easily adapted into any script, perhaps with caveats about the temporary filename not being the same, in order to avoid collisions if there are multiple instances running at the same time. It's possibly interesting to think about some unique filename pattern generation scheme, perhaps something along the lines of ${originalfilename}-jpgtrantmp-$$.

提交回复
热议问题