CodeIgniter Forums
Is there any way to crop larger? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Is there any way to crop larger? (/thread-24751.html)



Is there any way to crop larger? - El Forum - 11-18-2009

[eluser]Chad Crowell[/eluser]
I am uploading and resizing an image to 315x315, which is working fine. As expected, when the image is not square it is resizing to keep the aspect ratio, so something like 315x280. This is great.

After that happens I would like to crop the image to 315x315, so essentially it would center the image vertically, and add white background to the top and bottom to make it square, and then save it.

Is this possible?
How?


Is there any way to crop larger? - El Forum - 11-18-2009

[eluser]andrewtheandroid[/eluser]
[quote author="Chad Crowell" date="1258595610"]I am uploading and resizing an image to 315x315, which is working fine. As expected, when the image is not square it is resizing to keep the aspect ratio, so something like 315x280. This is great.

After that happens I would like to crop the image to 315x315, so essentially it would center the image vertically, and add white background to the top and bottom to make it square, and then save it.

Is this possible?
How?[/quote]

Do you need to crop it or can you display it with top and bototm vertically using css? you can make the container for the image 315x315 and set the padding or margins of the picture to make it center vertically.

As for actually for the image manip I havent really looked at that but maybe you could use GD to resize the canvas by creating a background image 315x315 white then merging it with your image?


Is there any way to crop larger? - El Forum - 11-18-2009

[eluser]BrianDHall[/eluser]
I've seen an ImageMagik PHP class that offers this sort of functionality, but given how few servers have IM installed (mine doesn't and it wasn't installing properly) I gave up on it. But if you have IM, it might be worth looking into.


Is there any way to crop larger? - El Forum - 11-19-2009

[eluser]andrewtheandroid[/eluser]
I think Ive seen an exmaple somewhere on google where they create a background (the canvas) then position the original image relative to the canvas then overlay the original onto the canvas (like a watermark? - with 100% opacity?)


Is there any way to crop larger? - El Forum - 11-19-2009

[eluser]andrewtheandroid[/eluser]
Looking at the CI image manipulation class I think you can use an image to watermark right? Maybe you can watermark a white 315x315 image.

In the user guide under overlay preferences you can use
Code:
wm_opacity 100
,

and watermarking preferences
Code:
// for the original
source image // your original pic
wm_vrt_alignment // set to middle
wm_hor_alignment // maybe not needed as same width

there may be some other preferences to play with like quality etc


Is there any way to crop larger? - El Forum - 11-19-2009

[eluser]Mat-Moo[/eluser]
Been playing with this today as well, watermark works perfect! Create a watermark same size as your thumbnail, save it as a JPEG (Don't use GIF!)
Code:
list($width,$height)=getimagesize($filenamedata["full_path"]);
            
            $config['source_image'] = $_SERVER[ 'DOCUMENT_ROOT' ].'/assets/blank100_100.jpg';
            $config['wm_overlay_path'] = $filenamedata["full_path"];
            $config['wm_type'] = "overlay";
            $config['wm_hor_offset']=round((100-$width)/2);
            $config['wm_vrt_offset']=round((100-$height)/2);
            $config['wm_opacity'] = 100;
            $config['new_image'] = $filenamedata["full_path"];
            $this->image_lib->initialize($config);
            if (!$this->image_lib->watermark())
            {
                print "watermark failed";
            }
Works great!


Is there any way to crop larger? - El Forum - 11-19-2009

[eluser]andrewtheandroid[/eluser]
oh nice! would we be able to put that whole chunk of code inside a foreach loop for all images?


Is there any way to crop larger? - El Forum - 11-19-2009

[eluser]Mat-Moo[/eluser]
as long as you add
Code:
$this->image_lib->clear();
at the start, I see no reason why not.


Is there any way to crop larger? - El Forum - 11-19-2009

[eluser]andrewtheandroid[/eluser]
thanks for sharing mat! this sounds like something i'd use in the future.