MagickSetImageFormat / MagickWriteImageFile

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

MagickSetImageFormat / MagickWriteImageFile

Post 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
Mikko Koppanen
My blog: http://valokuva.org
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: MagickSetImageFormat / MagickWriteImageFile

Post by dlemstra »

Have you tried to reproduce this problem with a newer version of ImageMagick?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: MagickSetImageFormat / MagickWriteImageFile

Post by mkoppanen »

I tested with the following version:

$ Wand-config --version
6.8.6 Q16
Mikko Koppanen
My blog: http://valokuva.org
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: MagickSetImageFormat / MagickWriteImageFile

Post 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.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply