Jimp: write() to a filename w/o image extension triggers a mimetype error

Created on 30 Mar 2016  路  7Comments  路  Source: oliver-moran/jimp

ex.

image.write( "tempfile" )

[Error: Unsupported MIME type: application/octet-stream]

Most helpful comment

@arminrosu is right. You need to state what kind of image you write to write: PNG, JPEG, BMP.

Right now, the file extension is used to determine what kind you want to write. The method could be extended to allow an explicit MIME type, like this:

image.write( "tempfile", Jimp.MIME_PNG);

Would you want that?

All 7 comments

How would you expect it to behave? Write .png, which is lossless, by default?

Without an extension it doesn't know which output image format to write to.

@arminrosu is right. You need to state what kind of image you write to write: PNG, JPEG, BMP.

Right now, the file extension is used to determine what kind you want to write. The method could be extended to allow an explicit MIME type, like this:

image.write( "tempfile", Jimp.MIME_PNG);

Would you want that?

My first thought was that without an extension, it would write using the source image's mime-type.

Either @arminrosu idea of extending the write method to image.write( "tempfile", Jimp.MIME_PNG); or adding an optional mime() method would work.

lenna.resize(256, 256)
   .quality(60)
   .greyscale()
   .mime(Jimp.MIME_PNG)                 // set optional mime-type
   .write("lenna-small");

Thinking about it a bit more, maybe the behaviors should be:

  1. Write to file based on mime-type set with mime()
  2. if mime-type is not set, write to file based on file extension
  3. if mime-type and file extension is not set, default to source file mime-type

hmm...

  1. explicit
  2. implicit
  3. somewhat ambiguous

ya, maybe #3 is not needed, your call. The ability to optionally set the output mime solve for most cases.

By the way, thumbs up on Jimp and thanks for putting it out there.

Sorry for not getting back sooner. I'm planning on doing a release later in the week. I'll add this issue to the list of issues to be addressed in the release after that.

the work around is to just add ".png" to the file path.

It is a shame to have to add an extension so that the program understands the format that one wants to use.
When storing files on the server, we do not necessarily use extensions because we can do a processing before delivering the file to the client.

how to get the output var name from Jimp
Jimp.read(array).then(function (lenna) {
lenna.resize(256, 256) // resize
.quality(60) // set JPEG quality
.greyscale() // set greyscale
.write("lenna-small"); // save

})

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Inbarasan16 picture Inbarasan16  路  3Comments

sesirimarco picture sesirimarco  路  3Comments

laino picture laino  路  5Comments

fatihturgut picture fatihturgut  路  4Comments

tutyamxx picture tutyamxx  路  4Comments