build a white image of the minimum size you want. then use the compare function to do a similarity match against the black and white image. specify a similarity resulting image which will have two components (-0 and -1). the second component (-1) will be the similarity score image. the brightest pixel in that image will be the upper left corner of black/white image where the white region best matches. every place that is fully white in the similarity image will correspond to the upper left corner of a perfectly white area of the minimum size.
see the compare example with mandril and its small eye image at
viewtopic.php?f=1&t=14613&hilit=compare+rmse
replace the eye image with the minimum size white image and the mandril with the black and white image.
see
http://www.imagemagick.org/script/compare.php
see also
http://www.imagemagick.org/script/comma ... -threshold as you may need to increase the default dissimilarity-threshold as you are comparing white to black areas which will be very dissimilar. If you need to use this you will get a message saying the images are too dissimilar.
This seems to work:
#create 100x100 pixel white image for comparison in the compare command
compare -metric rmse logo2.png -size 100x100 xc:white logo2_white_similarity.png
0 (0) @ 0,102
This says the first perfect match (rmse value =0) is at pixel 0,102
Here is the similarity image: logo2_white_similarity-1.png
The fully white area in the lower left corner corresponds to an area in the logo2.png image that is larger than 100x100 and completely white. So there is some room in the lower left corner of the logo2.png image to shift a 100x100 window around and still have it contain only white pixels.
If we threshold this image, then we see all the possible match coordinates for the 100x100 white area.
convert logo2_white_similarity-1.png -negate -threshold 0 -negate logo2_white_similarity-1_threshold.png
The coordinate of every white pixel here will correspond to the upper left corner of the 100x100 white image placement in the logo2.png image where it could be placed and match perfectly. That is a 100x100 window placed with its upper left corner at each of these coordinates in the logo2.png image would contain only white pixels.
The image below shows a black square of size 100x100 drawn starting with its upper left corner at the (first) match point identified above at 0,102
convert logo2.png -fill none -stroke black -draw "rectangle 0,102 99,201" logo2_square.png
So you can see there is some room to move the black outline around and still contain only white pixels. This is why the lower left area of the similarity score image is fully white.
With regard to APIs, I cannot really advise much. I do not know if this new similarity feature of compare is built into any of them. The API developers would have to comment.
However, you can do this either manually with the command line as above (or with a script) or putting the command lines in the exec function of PHP. For more details about using exec in PHP with IM, see
http://www.rubblewebs.co.uk/imagemagick/