Negative effect of running .png() on .jpg files?
See original GitHub issueI am in the process of optimizing lots of images, a mixture of both .png and .jpg images. Can I just run all the files through the same function?
sharp(files[c])
.png({...})
.jpeg({...})
.toBuffer(...)
So if the file is a PNG does it ignore the .jpeg() method and if it’s a JPG does it ignore the .png() method? Or do I need to determine the mime type ahead of time and use the appropriate method?
Is there any downside to doing this? Any negative affect on the files? Does it take a considerably longer time than if I checked the mime type ahead of time and used only the appropriate method for each mime type?
I am writing something that will be processing 1000’s of images at a time so I just want to get an idea of processing time one way or the other. The documentation just isn’t clear on this subject and I don’t see any examples or tests where both .png() and .jpeg() is used in the same chain.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)

Top Related StackOverflow Question
@polarathene Thanks for reporting, have created #1528 to track this.
@lovell great, so I shouldn’t need to try reproduce it any further? Is it a small fix to create? If you’re pressed for time I could try give it a go perhaps?
It should roughly involve knowing if a
force: truefor an image format in the chain had been declared earlier? Assuming you have something like an array of the format option objects that should be fairly easy to identify? 😃