Image icon indicating copy to clipboard operation
Image copied to clipboard

Return original width after resize

Open ssitdikov opened this issue 9 years ago • 11 comments

Hi.

For example, for code {{ image = image(photo).cropResize(120, 120) }} {{ image.width }} will be returned original width, but must be 120 or I am not right?

Reason is the using watermark images for photo-previews, so i need return correct new width/height data, but can't.

ssitdikov avatar Jul 21 '16 09:07 ssitdikov

I have encountered the same problem:

use Gregwar\Image\Image;

$in  = __DIR__.'/image-w800.jpg';
$out = __DIR__.'/image-w120.jpg';

$widths = [];

$image = Image::open($in);
$widths['original'] = $image->width();

$image->cropResize(120);
$widths['after-resize'] = $image->width();

$image->save($out);
$widths['after-save'] = $image->width();

print_r ($widths);
// Array ( [original] => 800 [after-resize] => 800 [after-save] => 120 )

hundblue avatar Dec 02 '16 16:12 hundblue

Can confirm this issue in the latest release

cord avatar Jan 20 '17 13:01 cord

This is because width() now is just an helper and doesn't apply the queued operations

Gregwar avatar Jan 20 '17 14:01 Gregwar

This could be fixed by applying the operations when calling width(), however this would violate the interest of the cache system in this case Can you describe me your use case so I can think a solution for this?

Gregwar avatar Jan 20 '17 14:01 Gregwar

Ok, with a meta-data api call I want to get the dimensions of the generated images by cacheId. I tried to apply images( resource $image) , imagesy( resource $image) but failed to retrieve resource $image after creating the image with $img->png(). Any advice?

cord avatar Jan 20 '17 14:01 cord

When you use cache, if there is already the file in cache absolutely no files are opened currently I think in the current release width() will work the first time because the image is generated but will still be the original width the second time I can fix that, however note that calling width() will then cost extra performances since this will open the cached file

Gregwar avatar Jan 20 '17 14:01 Gregwar

Should be optional.

Scenario: generating and outputting responsive images with 2x resolution, so the html() method should generate something like this:

<img src="{cacheUrl}" width="{imgWidth/2}" height="{imgHeight/2}">

cord avatar Jan 20 '17 14:01 cord

I did a change so that calling width() and height() after generating cache should work now

Gregwar avatar Jan 20 '17 14:01 Gregwar

Example:

$img = Image::open('test.jpg')->cropResize(50, 50);
$img->width(); // Width pre-resize
$img->png();
$img->width(); // Width post-resize

Gregwar avatar Jan 20 '17 14:01 Gregwar

thanks a lot, works perfectly!

cord avatar Jan 24 '17 08:01 cord

Is this a viable solution? Why issue is still open? Some drawbacks?

Karmalakas avatar Mar 12 '21 17:03 Karmalakas