I'm using the MagickCore API.
Suppose I know I want the format of an image to be JPEG and I want to write the image to a file named "tmp/test.6543.0". How do I make WriteImage write the image in JPEG format?
Currently I store "JPEG" in the image_info->magick field and then call SetImageInfo, but the trailing ".0" on the filename confuses SetImageInfo into setting the image_info->magick field to "0". If I skip the call to SetImageInfo, leaving image_info->magick set to "JPEG" and image->magick set to the current image format, then WriteImage writes the image in the current format, not JPEG.
What am I doing wrong?
How do I force the output format?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: How do I force the output format?
write the image to a filename with a 'format prefix. For example "jpg:tmp/test.6543.0". The prefix is not written, but overides any trailing suffix in the filename.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: How do I force the output format?
Well, I don't really have any control over the output filename. It would be nice to be able to specify the output format via some other channel, like the image_info->magick field.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: How do I force the output format?
Just take the output filename, and copy it to a new string with the prefix, before using it. Otherwise insist that the supplier of the filename produces one with the right suffix!!!
I mean you really shouldn't have files with bad suffixes, even temporary files. It is bad programming and data handling.
I mean you really shouldn't have files with bad suffixes, even temporary files. It is bad programming and data handling.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: How do I force the output format?
Thanks for your reply, Anthony. I don't think I'll have much luck persuading the Ruby folks to change the format of temporary file names, so I suppose I'll have to go the route of adding the format as a prefix to the filename. I want to think about what to do in the case that the program specifies the "JPEG" format and the output filename is "gif:foo.bar".
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: How do I force the output format?
You should be able to use "jpg:gif:foo.bar" testing...
It created the file gif:foo.bar
It is only some special output formats (like histogram: ) that would look for another prefix after its own.. EG: -format '%c' histogram:info:- See http://imagemagick.org/Usage/files/#histogram
Shows it is indeed a JPEG image file!!!
identify works too.
Looks like image input first trys the given string as a filename before looking for a format prefix hint! to define the type of file.
Of course you can fix that by using file redirection
In shell this is...
Code: Select all
convert rose: jpg:gif:foo.bar
It is only some special output formats (like histogram: ) that would look for another prefix after its own.. EG: -format '%c' histogram:info:- See http://imagemagick.org/Usage/files/#histogram
Code: Select all
file gif:foo.bar
Code: Select all
identify gif:foo.bar
Looks like image input first trys the given string as a filename before looking for a format prefix hint! to define the type of file.
Of course you can fix that by using file redirection
In shell this is...
Code: Select all
identify - < gif:foo.bar
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/