Page 1 of 1
How do I force the output format?
Posted: 2008-07-16T16:18:40-07:00
by rmagick
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?
Re: How do I force the output format?
Posted: 2008-07-16T16:47:02-07:00
by anthony
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.
Re: How do I force the output format?
Posted: 2008-07-16T17:09:57-07:00
by rmagick
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.
Re: How do I force the output format?
Posted: 2008-07-16T21:23:26-07:00
by anthony
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.
Re: How do I force the output format?
Posted: 2008-07-17T15:36:15-07:00
by rmagick
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".
Re: How do I force the output format?
Posted: 2008-07-17T18:25:00-07:00
by anthony
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...