any processing hit for convert to same name same format

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tobycarr

any processing hit for convert to same name same format

Post by tobycarr »

Hi,
If I do a

Code: Select all

convert image.png image.png
will the line be skipped as it achieves nothing or does it incur some processing?
Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: any processing hit for convert to same name same format

Post by fmw42 »

I believe it will reprocess the image. But I will defer to the experts.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: any processing hit for convert to same name same format

Post by Bonzo »

I belive if you did that with a jpg image it would read the image in and resave it with jpg compression over the original.
Why don't you try it with a jpg and see what happens ?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: any processing hit for convert to same name same format

Post by anthony »

Actually I am not entirely sure.

If the image in memory is NOT processed in some way. That is the image data does not become 'tainted' then IM should simply read and write the image data AS IS without processing it. This is especially the case when an image is involved with delegates.

This was discovered when someone wanted to convert a "AI" image file (actually a type of postscript file) into a "EPS" file (Encapulated Postscript). IE just copied the file instead of converting the image to a raster in memory, then writing that. That is the EPS was a vector image, and not a vector wrapped raster image!

This was part of IM's original 'convert' functionality!

If you want to FORCE imagemagick to actually write the image that is in memory, you can use the -taint operator to make it thik it has been modified!

However in this case, no delegates are involved, and the input and output image are the same filename, so it may be that IM will open the file for read, then open a NEW file to replace the existing file, and transfer the data directly AS IS.

OKAY definitave test. create a PNG image and collect info on it...

Code: Select all

convert rose: r.png
strings r.png | tail -5
%tEXtcreate-date
2009-05-14T11:33:59+10:00
%tEXtmodify-date
2009-05-14T11:33:59+10:00
IEND
ls -Fla r.png
-rw------- 1 anthony anthony 6939 2009-05-14 11:34 r.png
now wait a minute or so for time to pass, then try it...

Code: Select all

convert r.png r.png
Now look at the file again.

Code: Select all

strings r.png | tail -5
%tEXtcreate-date
2009-05-14T11:39:56+10:00ry
%tEXtmodify-date
2009-05-14T11:39:56+10:00-
IEND
ls -Fla r.png
-rw------- 1 anthony anthony 6939 2009-05-14 11:42 r.png
As the strings in the file itself changed IM did actually read in and write out the file through memory.
As such if delegates (or pipelines) are NOT involved, IM will process the image via memory.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
tobycarr

Re: any processing hit for convert to same name same format

Post by tobycarr »

Thanks for thorough answers here Anthony et al.

SO my next question on this, if you wouldn't mind, is ..
then is there an option/s that can go between

Code: Select all

convert image.png
and

Code: Select all

image.png
that will make sure nothing happens on that line ..sort of like a NULL code that won't produce an error, won't do anything to the image and will take minimum processing time .. (and if possible.. wouldn't effect any other following commands on the same line if there were any??)
e.g.

Code: Select all

convert image.png donothing image.png
ta
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: any processing hit for convert to same name same format

Post by anthony »

When re-generating examples in IM Examples I faced a problem of attempting to determine if a freshly generated example image was the same as the previously generated image.

If they were the same I restored the original one (unless I flagged it not to)

But if they were different (difficult with JPEG and multi image GIF animations) then
notify me they the example had unexpectedly changed.

This system of keeping the original file saves me a LOT of bandwidth when I upload my changes to an intermediate host for collection to use on the offical website. But it has also greatly benefited IM Users when some software change cause unexpected problems, breaking accepted practice. It allowed us to fix new problems before the new update is released.

Of course if a software change, say modified text rendering I can get 50% of all the examples changing in some way, meaning a lot of work seperating the accepted change from a unexpected change.

However in your case it sounds like you want to do the same type of thing. You don't want to replace the old original image if the command did not generate a new image.

The script is hidden but online at http://www.imagemagick.org/Usage/generate_compare
And basically works like this
The original image is saved by prefixing a underscore.
EG:
mv image.png _image.png

The examples are regenerated to create (or fail to create) a new "image.png"

this script then compares "_image.png" with "image.png" and decided to either restore the old image on no change, or report if a change has happened (if large enough).

its first handles special images (usally text and multi-image GIF animations)
Then checks the image sizes
then the image contents.

Different image formats are handled differently. and that is where the trickiness comes in.
Some images like PNG has a creation date, and that means the image file is always different,
as such I can not simply compare the image files directly.

The image data is thus compared using
compare -metric PAE $new $old null: 2>&1
to get a number on just how different the results are. Usually it is zero, but not always.
For example a jpeg library upgrade could cause minor differences.

That is all I can suggest for you.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
tobycarr

Re: any processing hit for convert to same name same format

Post by tobycarr »

That's really great - thanks for all that Anthony..I will go from there
Post Reply