andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Crop by color attributes

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Crop Canvas
View previous topic :: View next topic  
Author Message
frey1esm
Newbie


Joined: 15 Mar 2004
Posts: 3

PostPosted: Mon Mar 15, 2004 1:39 am    Post subject: Crop by color attributes Reply with quote

Hi Andy,

Is there away to use your class to trim a border off an image?

For example, say there is a scan of a polaroid, and we want to extract the photo and discard the white border from the polaroid, can that be done?

Thanks,

-David
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Mar 15, 2004 5:25 am    Post subject: Reply with quote

hi there,

Yes, there is a way to automatically crop an image, but it's based on a threshold limit rather than colour. (I'm glad someone is looking into this function, because it's one of my favourite as I've not seen it in any other PHP cropping tool. Wink )

The function you want is cropByAuto which takes one parameter, the level of the threshold.

Code:
    /**
    * @return bool
    * @param int $threshold
    * @desc Determines the dimensions to crop to if using the 'automatic crop by threshold' method
    */
    function cropByAuto($threshold = 254)


The default of the crop threshold, as you can see, is 254. That should pretty much crop all the pure white from the borders of the image. It will crop in until it finds anything (even one pixel!) that doesn't cross the threshold and stop at those dimensions.

Try playing around with that and seeing if it works out for you.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
frey1esm
Newbie


Joined: 15 Mar 2004
Posts: 3

PostPosted: Mon Mar 15, 2004 8:28 am    Post subject: Determining start position Reply with quote

Thanks Andy. That funtion could be the ticket, but how do you set the proper start position? It's automatically using ccTOPLEFT.


-David
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Mar 15, 2004 9:18 am    Post subject: Reply with quote

That is the correct starting position (at least, in my mind it is!)

The cropping will 'shrink' the image on all sides; top, left, right, and bottom. In that sense it doesn't matter if the cropping takes place at the top left or bottom right, because the result is the same. So, to me, it just makes perfect sense to start at the top left corner and work down.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
frey1esm
Newbie


Joined: 15 Mar 2004
Posts: 3

PostPosted: Mon Mar 15, 2004 9:46 am    Post subject: Not shrinking all sides Reply with quote

Hi again!

That's the problem...it is not cropping all sides. It's cropping the right and bottom. The white borders are still left on the top and left.

-David
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Mar 15, 2004 11:27 am    Post subject: Reply with quote

It's probably not cropping those two borders because it's finding a pixel that doesn't cross the threshold limit. What the script does is generates a black and white image based on your threshold limit and then goes one pixel at a time over that image to see where the first occurrence of a pixel is that is black. If it finds that then it sets that dimension as what it will crop at.

Because it's a polaroid you're scanning, chances are it's not going to be pure white around the borders (might look it to you, but it might not be in actual colour values). Try turning down your threshold limit a little bit. Go one or two pixels down until you find the setting that best suits your needs.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Crop Canvas All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group