php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58667 thumbnailImage() (and others) with $fit = true overscale image
Submitted: 2009-05-11 10:40 UTC Modified: 2009-07-02 18:17 UTC
From: glen at delfi dot ee Assigned:
Status: No Feedback Package: imagick (PECL)
PHP Version: 5.2.9 OS: PLD Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: glen at delfi dot ee
New email:
PHP Version: OS:

 

 [2009-05-11 10:40 UTC] glen at delfi dot ee
Description:
------------
http://php.net/manual/en/function.imagick-thumbnailimage.php
documents: 

"If TRUE is given as a third parameter then columns and 
rows parameters are used as maximums for each side. Both 
sides will be scaled down until the match or are smaller 
than the parameter given for the side."

however having input image with 401x600 pixels, scaled 
down to 250x600, results me given image 401x600. it seems 
it's due the macro reseting desired_width to 0, thus 
losing the information given as $width parameter.

php_imagick_macros.h :
#define IMAGICK_CALCULATE_THUMBNAIL_SIDES(magick_wand, 
desired_width, desired_height, fit) \
....
        } else { \
            if (orig_height > orig_width) { \
                desired_width = 0; \
            } else { \
                desired_height = 0; \
            } \


Reproduce code:
---------------
// create sample image:
$ convert -size 401x600 plasma:fractal foo.jpg
// run the script:
$ php test.php
original: w=401; h=600
result: w=401; h=600

// script itself:
$ cat test.php
<?php
$input_file = 'foo.jpg';
$width = 250;
$height = 600;

$im = new Imagick();
$im->readImage($input_file);
echo "original: w={$im->getImageWidth()}; h={$im->getImageHeight()}\n";
$im->thumbnailImage($width, $height, true);
echo "result: w={$im->getImageWidth()}; h={$im->getImageHeight()}\n";


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-11 10:43 UTC] glen at delfi dot ee
i workarounded problem for myself disabling the $fit = 
true and supplied properly calculated dimensions:

<?php
    $ow = $im->getImageWidth();
    $oh = $im->getImageHeight();

    // take the smallest proportion and use that as size 
ratio multiplier
    $ratio = $width / $ow < $height / $oh ? $width / $ow : 
$height / $oh;
    $width = floor($ow * $ratio);
    $height = floor($oh * $ratio);
 [2009-05-13 18:02 UTC] mkoppanen@php.net
Hi, can you test the CVS version?
 [2009-05-14 05:20 UTC] glen at delfi dot ee
i tested also with 2.3.0RC1, the code was not changed in that
header file.
 [2009-05-14 05:29 UTC] mkoppanen@php.net
CVS:

cvs -d :pserver:cvsread@cvs.php.net/repository checkout pecl/imagick && cd pecl/imagick && phpize && ./configure && make install
 [2009-05-14 05:40 UTC] glen at delfi dot ee
unfortunately i can't test right now, seems i need to upgrade
imagick first (i have 6.2.9.1 installed):


/home/glen/rpm/pld/BUILD/imagick/imagick_read.c:304:2:
warning: no newline at end of file
/home/glen/rpm/pld/BUILD/imagick/imagick_read.c: In function
`php_imagick_format_indicator':
/home/glen/rpm/pld/BUILD/imagick/imagick_read.c:94: error:
too few arguments to function `count_occurences_of'
make: *** [imagick_read.lo] Error 1
make: *** Waiting for unfinished jobs....
/home/glen/rpm/pld/BUILD/imagick/imagick_helpers.c: In
function `php_imagick_validate_map':
/home/glen/rpm/pld/BUILD/imagick/imagick_helpers.c:133:
warning: initialization discards qualifiers from pointer
target type
/home/glen/rpm/pld/BUILD/imagick/imagick_helpers.c: In
function `initialize_imagick_constants':
/home/glen/rpm/pld/BUILD/imagick/imagick_helpers.c:1050:
error: `OptimizeImageLayer' undeclared (first use in this
function)
/home/glen/rpm/pld/BUILD/imagick/imagick_helpers.c:1050:
error: (Each undeclared identifier is reported only once
/home/glen/rpm/pld/BUILD/imagick/imagick_helpers.c:1050:
error: for each function it appears in.)
/home/glen/rpm/pld/BUILD/imagick/imagick_helpers.c:1051:
error: `OptimizeTransLayer' undeclared (first use in this
function)
/home/glen/rpm/pld/BUILD/imagick/imagick_helpers.c:1052:
error: `RemoveDupsLayer' undeclared (first use in this
function)
/home/glen/rpm/pld/BUILD/imagick/imagick_helpers.c:1053:
error: `RemoveZeroLayer' undeclared (first use in this
function)
/home/glen/rpm/pld/BUILD/imagick/imagick_helpers.c:1054:
error: `CompositeLayer' undeclared (first use in this
function)
make: *** [imagick_helpers.lo] Error 1
error: Bad exit status from /home/glen/tmp/rpm-tmp.95759
(%build)
 [2009-05-14 06:01 UTC] mkoppanen@php.net
Should be fixed now. Can you retest? Build against thread safe php was broken (i hardly ever test it)
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Nov 16 22:01:35 2019 UTC