php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58515 ico format not working on Imagick::readImageBlob
Submitted: 2009-01-20 19:05 UTC Modified: 2009-06-17 19:38 UTC
From: guozheng dot ge at gmail dot com Assigned:
Status: Not a bug Package: imagick (PECL)
PHP Version: 5.2.5 OS: rhel-4.x
Private report: No CVE-ID:
Password:
Status:
Package:
Bug Type:
Summary:
From: guozheng dot ge at gmail dot com
New email:
PHP Version: OS:

 

 [2009-01-20 19:05 UTC] guozheng dot ge at gmail dot com

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-21 05:50 UTC] mkoppanen@php.net
Try calling $im->setFormat("ico"); before readImageBlob(). Does this help?
 [2009-01-21 17:32 UTC] guozheng dot ge at gmail dot com
tried to setImageFormat('ico') before readImageBlob, it 
returns an exception saying cannot perform it on an empty 
Imagick object.

exception happened ImagickException Object ( 
[message:protected] => Can not process empty Imagick object 
[string:private] => [code:protected] => 1 [file:protected] 
=> /home/y/share/htdocs/testimagick.php [line:protected] => 
24 [trace:private] => Array ( [0] => Array ( [file] => 
/home/y/share/htdocs/testimagick.php [line] => 24 [function] 
=> setimageformat [class] => Imagick [type] => ->  [args] => 
Array ( [0] => ico ) ) ) )
 [2009-01-21 18:37 UTC] mkoppanen@php.net
setFormat, not setImageFormat.
 [2009-01-22 13:20 UTC] guozheng dot ge at gmail dot com
Hi, Mikko

Thanks a lot for the quick replies and great work on imagick ;-)

I tried setFormat('ico'), now, I don't get "cannot process empty Imagick object" exception anymore. But still I cannot get the ico image output correctly. The output is an ugly looking image (maybe this is because ico has multiple images embedded inside?). Here is the code I tried:

        $imageStr = file_get_contents('favicon.ico');
        $im = new Imagick();
        $im->setFormat('ico');
        $im->readImageBlob($imageStr);
        $im->setImageFormat('png');
        header('Content-type: image/x-icon');
        echo $im; 

Previously, when I create an Imagick object from file using constructor and then setImageFormat('png'), it worked fine and I can get a 24x24 image. Here is the code that works for comparison:

        $im = new Imagick('favicon.ico');
        $im->setImageFormat('png');
        header('Content-type: image/x-icon');
        echo $im;

thanks!
 [2009-02-06 16:30 UTC] mkoppanen@php.net
Sorry, but your problem does not imply a bug in PECL itself.  For a
list of more appropriate places to ask for help using PECL, please
visit http://pecl.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PECL.

Imagick passes the image to ImageMagick for processing and usually can not affect the quality of output except by setting some properties. Therefore I am closing this bug.
 [2009-06-17 14:06 UTC] guozheng dot ge at gmail dot com

 [2009-06-17 15:21 UTC] mkoppanen@php.net
I am not sure I fully understand what the problem is here.
 [2009-06-17 16:36 UTC] guozheng dot ge at gmail dot com
Thanks for the quick reply. 

I guess the problem here is that when you convert ICO image 
as a whole to other formats, it does not work and creates 
crappy results.

So, you need to get one of the images contained inside the 
ICO image and convert the individual image.

But I still don't understand why when you write the ICO 
image content to a file then read from the file, the 
conversion works fine.
 [2009-06-17 16:45 UTC] mkoppanen@php.net
Have you tried flattenImages to merge the layers? Image formats which have multiple images in them are presented in this way because it is the only way to access the individual frames if needs be.
 [2009-06-17 19:38 UTC] guozheng dot ge at gmail dot com
identify ../favicon.ico 
../favicon.ico[0] ICO 32x32 32x32+0+0 DirectClass 8-bit 
6.44336kb 
../favicon.ico[1] ICO 16x16 16x16+0+0 DirectClass 8-bit 
6.44336kb 
../favicon.ico[2] ICO 48x48 48x48+0+0 DirectClass 8-bit 
6.44336kb 
../favicon.ico[3] ICO 24x24 24x24+0+0 DirectClass 8-bit 
6.44336kb

create imagick obj from image string then do flattenImages, 
it returns a normal ICO image, but the result is the size of 
the first image inside the ICO, 32x32 in this case

If you open the ICO file in the browser directly, you get a 
different size, 16x16

I also tried to read from ICO file directly, it outputs the 
last image inside the ICO, 24x24

So, I guess either using flattenImages or traversing through 
individual images both will work. But not really sure what 
should be the correct size. Maybe it is upto the user 
requirement.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC