Joshua4550 Posted July 14, 2010 Share Posted July 14, 2010 Hi, I have recently been reading through some of the functions in the GD library, and custom functions people have built off of that. I was wondering if there's a way, with or without the GD library, to get an image and crop it for "fit to canvas"? Such a feature would remove unnecessary transparrent canvas. For example if you had a 500x500 canvas, but the image inside of it was only 200x300, it would crop the image down to 200x300. Is this possible? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/207677-remove-transparrency-fit-to-canvas/ Share on other sites More sharing options...
Joshua4550 Posted July 14, 2010 Author Share Posted July 14, 2010 Oh, and I forgot to mention:- I know I could crop it and output it, but I don't ALWAYS want those exact dimensions - they were just an example. I need a method which would work on all sizes. Is this possible?? Quote Link to comment https://forums.phpfreaks.com/topic/207677-remove-transparrency-fit-to-canvas/#findComment-1085649 Share on other sites More sharing options...
Spring Posted July 14, 2010 Share Posted July 14, 2010 I'm having the same problem Quote Link to comment https://forums.phpfreaks.com/topic/207677-remove-transparrency-fit-to-canvas/#findComment-1085660 Share on other sites More sharing options...
Joshua4550 Posted July 14, 2010 Author Share Posted July 14, 2010 Does no one know if this is possible? Quote Link to comment https://forums.phpfreaks.com/topic/207677-remove-transparrency-fit-to-canvas/#findComment-1085712 Share on other sites More sharing options...
Alex Posted July 14, 2010 Share Posted July 14, 2010 Yes, it's possible. As long as there's no transparency within the part of the image you want to keep it would be pretty easy. You'll need to go over the image and find out the coordinates for where it starts, and where it ends. Some functions you should look into: imagecolorat imagecolorsforindex You can use those to determine if a particular point is transparent or not. (For transparent pixels the alpha will be 127.) Once you determine those 2 points you can easily crop the image to what you want. Quote Link to comment https://forums.phpfreaks.com/topic/207677-remove-transparrency-fit-to-canvas/#findComment-1085714 Share on other sites More sharing options...
Joshua4550 Posted July 14, 2010 Author Share Posted July 14, 2010 Thank you so much, i'll start looking into it right now =) Quote Link to comment https://forums.phpfreaks.com/topic/207677-remove-transparrency-fit-to-canvas/#findComment-1085716 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.