Welcome Guest, Not a member yet? Register   Sign In
Is there any way to crop larger?
#1

[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?
#2

[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?
#3

[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.
#4

[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?)
#5

[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
#6

[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!
#7

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB