question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Negative effect of running .png() on .jpg files?

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lovellcommented, Jan 1, 2019

@polarathene Thanks for reporting, have created #1528 to track this.

0reactions
polarathenecommented, Jan 1, 2019

@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: true for 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? 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

JPEG vs. PNG: Why Image Formats Matter for a Fast Website
JPG vs PNG - Which format should you use to keep your website blazing fast? Read this post to learn the most important...
Read more >
JPG vs. PNG: Which Should I Use? | The TechSmith Blog
Some quality is compromised when an image is converted to a JPG. The reason is because the compression is lossy, which means that...
Read more >
JPG vs JPEG: Understanding the Most Common Image Format
The file size of the image being compressed is permanently reduced by eliminating unnecessary (redundant) information from the image. Image ...
Read more >
Which image format is better for machine learning .png .jpg or ...
JPG files will usually be smaller due to compression. PNG files will retain their original image more accurately. Depending on your data source, ......
Read more >
JPEG versus PNG: The Best Choice for Product Photography
When an image is converted into a JPG from its original format such as RAW, some quality is compromised. The reason is because...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found