Square cropping from the center, is there an easier way? RESOLVED |
[eluser]JoostV[/eluser]
Hi, I need to generate square thumbs for an image gallery. The cropping has to be done from the center. E.g. horizontal cropping would take a bit of the left side and off the right side of the image. I tried using negative values for cropping, but it didn't work. I found a solution for now, but I am not happy with it. I am sure there must be an easier way. The way I do it now: * Flip the image using $this->image_lib->rotate() ('hor' for cropping on x-axis, 'vrt' for cropping on y-axis) * Crop from one side using $this->image_lib->crop() * Flip again * Crop from the other side Anyone know a better solution? Tnx in advance.
[eluser]Référencement Google[/eluser]
Your way to do it is too complex. Look at this thread: http://ellislab.com/forums/viewthread/73906/ I think the best is to get first the image properties (width and height), you can use something like : Code: // Get the Image properties (this function is not documented in CI manual) Then the next is mathematics, divide by 2 the width and height and add to this the width and height of the desired cropped size. If you don't find, please post some code here.
[eluser]JoostV[/eluser]
Ah I see! The trick is to set width and height and adding $config['maintain_ratio'] = false; I never tried this because, according to the User Guide, maintain_ratio is not used by $this->image_lib->crop(); Now it's just a matter of one or two extra lines of code. Thanks very much! Code: //Set config for img library $fileData is result array from uploading image using libary File Upload |
Welcome Guest, Not a member yet? Register Sign In |