Page 1 of 1

MagickSetImageFormat / MagickWriteImageFile

Posted: 2013-09-29T00:11:20-07:00
by mkoppanen
Hello,

following bug was reported against Imagick: Bug #64208 [Com]: writeImageFile does not respect setImageFormat (https://bugs.php.net/bug.php?id=64208)

It seems that this is not Imagick specific but can be reproduced with MagickWand API:

Code: Select all

#include <wand/MagickWand.h>
#include <assert.h>

int main () {
    MagickBooleanType rc;

    MagickWand *w = NewMagickWand ();
    assert (w);

    rc = MagickReadImage (w, "test.jpg");
    assert (rc == MagickTrue);

    FILE *fp = fopen ("out.png", "w+");
    assert (fp);

    rc = MagickSetImageFormat (w, "png");
    assert (rc == MagickTrue);

    char *format = MagickGetImageFormat (w);
    fprintf (stderr, "Format: %s\n", format);
    MagickRelinquishMemory (format);

    rc = MagickWriteImageFile (w, fp);
    assert (rc == MagickTrue);
    fclose (fp);

    return 0;
}
Output:

$ cc -o wand `pkg-config --cflags --libs MagickWand` wand.c
$ ./wand
Format: png
$ file out.png
out.png: JPEG image data, JFIF standard 1.01

Re: MagickSetImageFormat / MagickWriteImageFile

Posted: 2013-09-29T03:27:13-07:00
by dlemstra
Have you tried to reproduce this problem with a newer version of ImageMagick?

Re: MagickSetImageFormat / MagickWriteImageFile

Posted: 2013-09-29T22:57:14-07:00
by mkoppanen
I tested with the following version:

$ Wand-config --version
6.8.6 Q16

Re: MagickSetImageFormat / MagickWriteImageFile

Posted: 2013-10-01T04:21:34-07:00
by dlemstra
The method 'MagickWriteImageFile' uses the filename property of NewMagickWand to determine the output type. You should change this to modify the format of the output file.