Page 1 of 1

Detect background color and create square image

Posted: 2014-12-18T14:32:12-07:00
by crc863
Hi everyone!

I may be asking too much here but let me explain what I'm trying to do.

1.) User uploads photo
2.) Detect if the image has a solid background (most likely a logo) or if not (most likely a photograph)
3.) If it's a logo with a solid background, determine the background color
4.) if the image is not a perfect square, and a "logo" make the image a square using the script below with the determined background color.

Code: Select all

<?php
exec('convert '.ROOT.UPLOADS_IMGS.'2014/12/18/9360011418937327.jpg \
        \( +clone -rotate 90 +clone -mosaic +level-colors white \) \
         +swap -gravity center -composite '.ROOT.UPLOADS_IMGS.'2014/12/18/9360011418937327-bg.jpg');
?>
Is this possible with imagemagick?

Re: Detect background color and create square image

Posted: 2014-12-18T15:17:55-07:00
by snibgo
crc863 wrote:2.) Detect if the image has a solid background (most likely a logo) or if not (most likely a photograph)
If the input is JPG, it won't have a solid background. It might have a nearly solid background. You might detect this by flood-filling from (0,0) with a fuzz factor, and counting the proportion of pixels that have changed, or seeing if all border pixels have changed, or some other test.