Closed circuitmamu closed 8 years ago
Have you tried crop
?
$image = new Image('test.jpg');
$image
->resize('crop', 240)
->generate('output-image.jpg');
yes I tried but it crop the portion of the image I want whole image if it stretch then it will allow
So.. you don't want to maintain the aspect ratio?
it will not work it will 169x240 thumbs
Please, be more specific... I can't get what you're trying (and I guess it's probably due to a communication problem).
Please, see this issue #4 as an example of how to create new issues.
I just want to make below things
I tried the resize or classicResize but it is not it generate the thumb of 169*240 becasue actual image test.jpg size 2480 x 3508
In this case height is more than width so when use resize or classicResize it will maintain ratio and generate 169*240.
when I use ->resize('crop', 240) it will generate exact 240px * 240px but it will still maintain ration.
If image will stretch then it is okay but still this class doesn't work for me where I do not want to maintain ratio.
There's no method to directly do that with Watimage, but you can treat your images directly and easily resize them using imagecopyresampled
:
<?php
use Elboletaire\Watimage\Image;
$image_file = 'input.jpg';
// load image to be resized
$image = new Image($image_file);
// generate a new canvas of the desired resize size
$newImage = new Image();
$newImage->create(250, 250);
// Get the resource objects
$resource = $image->getImage();
$resource2 = $newImage->getImage();
// Obtain original image metadata (we need its height and width)
$metadata = $image->getMetadata();
// Copy to destiny resizing without maintaining aspect ratio
imagecopyresampled($resource2, $resource, 0, 0, 0, 0, 250, 250, $metadata['width'], $metadata['height']);
// Return the image resource to the Image instance
$newImage->setImage($resource2)
// and save
->generate('resized.jpg');
actual image test.jpg size 2480 x 3508
use Elboletaire\Watimage\Image; $image = new Image('test.jpg'); $image ->resize('resizecrop', 240) ->generate('output-image.jpg');
Using above line of it will generate thumg of 240x240 but it will maintain aspect ratio.
But I when use ->resize('resize', 240) it will generate the 169x240 thumb in this case height is consider as aspect ration parameter and image will not been cropped.
I want to make a thumb of 240 x 240 strict height and width but do not want to exceed the both parameter and also image do not follow aspect ratio parameter.
If image will starch in height and width then it will be allow if any direct function or changes suggestion then please let me know so I can use this class.