elboletaire / Watimage

:framed_picture: PHP image manipulation class
https://elboletaire.github.io/Watimage
Other
25 stars 17 forks source link

want to generate image without maintain aspect ration #29

Closed circuitmamu closed 8 years ago

circuitmamu commented 8 years ago

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.

elboletaire commented 8 years ago

Have you tried crop?

$image = new Image('test.jpg');
$image
    ->resize('crop', 240)
    ->generate('output-image.jpg');
circuitmamu commented 8 years ago

yes I tried but it crop the portion of the image I want whole image if it stretch then it will allow

elboletaire commented 8 years ago

So.. you don't want to maintain the aspect ratio?

circuitmamu commented 8 years ago

it will not work it will 169x240 thumbs

elboletaire commented 8 years ago

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.

circuitmamu commented 8 years ago

I just want to make below things

  1. upload image which is submited by user in $_FILES
  2. process that image and add watermark on that image before save with 75% of image width.
  3. after save the image I want to make a thumbnail of exact 240px x 240px (don't want to maintain aspect ration).

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.

elboletaire commented 8 years ago

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');