Not able to get standard Picture size to compare two Images

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
aryan05
Posts: 8
Joined: 2014-08-28T10:38:27-07:00
Authentication code: 6789

Not able to get standard Picture size to compare two Images

Post by aryan05 »

All,
I am currently using Webdriver tool to get screenshot of a Webpage. I'm using Firefox browser to host the webapage.
The issue i am facing while comparing two images in ImageMagick is that the size of screenshots vary.

To overcome this, i explicitly try "convert" command and update Image to standard size like shown below .

convert "src/main/resources/Images/ImagesGoldenSet/Image.png" -resize 1024x1024 "src/main/resources/Images/ImagesGoldenSet/Image.png"

and then when I try to compare two images who have been converted as above, i still see the Image size varies minutely like shown below.

Image1 Size: PNG 324x1024 324x1024+0+0 16-bit sRGB 1.009MB 0.000u 0:00.000
Image2 Size: PNG 329x1024 329x1024+0+0 16-bit sRGB 967KB 0.016u 0:00.000

As you see above, both image sizes have 1024, but i still see a difference "324x1024" and "329x1024".

Question - How do i achieve a exact same Image size when converting and how do i overcome the 'compare' issue when size is slightly different.
Any other better way to achieve a solution.


Cheers
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Not able to get standard Picture size to compare two Images

Post by snibgo »

Use "!" to force an exact resize. For example ...

Code: Select all

convert in.png -resize 1024x1024! out.png
... will make the output exactly 1024x1024 pixels.

For some shells, we need to escape the "!". For example, Windows BAT syntax:

Code: Select all

convert in.png -resize "1024x1024^!" out.png
snibgo's IM pages: im.snibgo.com
Post Reply