Converting Jpeg to Png resulting in bloated file size

Questions about the project and the distribution - obviously no support questions here please
Post Reply
FOSSguy_1x
Level 1
Level 1
Posts: 30
Joined: Thu Jan 28, 2021 3:50 pm

Converting Jpeg to Png resulting in bloated file size

Post by FOSSguy_1x »

I was going to put this in the software section but I found out that it is not limited to the default "Image Viewer" application that comes with Linux mint. Ive tried several applications and some of the result in bloated file sizes even after changing the compression level of png. Any tips or programs I can use instead?

I've tried pix for example and this is one of my examples I have seen so far
image resolution 723 x 1024 jpeg 160.1 kB ---> converted using compression level 9 results in a 1.3 MB file.

example 2 using Image Viewer "save as" to convert a jpg image to a png image
395 x 679 87.4 kB ----> 495.4 kB

It may seem small but it adds up when using thumbnail images for your emulation playlists.
User avatar
absque fenestris
Level 11
Level 11
Posts: 3583
Joined: Sat Nov 12, 2016 8:42 pm
Location: Confoederatio Helvetica

Re: Converting Jpeg to Png resulting in bloated file size

Post by absque fenestris »

FOSSguy_1x wrote:
Thu Aug 19, 2021 7:18 am
...
It may seem small but it adds up when using thumbnail images for your emulation playlists.
...and also comparable results with GIMP. The PNG format is not really economical - or in other words, the JPG algorithm is already incredibly sophisticated - and WEBP picks up where JPG leaves off...

Does it have to be PNG?
Linux Mint 18.3 Sylvia (MATE) 32-bit - Acer D250 Netbook
Linux Mint 20.0 Ulyana (Cinnamon) - Huawei MateBook X Pro
rene
Level 18
Level 18
Posts: 8083
Joined: Sun Mar 27, 2016 6:58 pm

Re: Converting Jpeg to Png resulting in bloated file size

Post by rene »

It's fundamental; PNG is lossless image compression, JPG lossy. That is, given a source image, JPEG compression discards all sorts of information from the source image; a JPG to PNG conversion then first decompresses the JPG to a "mere facsimile" of the original image without all that discarded data, after which PNG compression goes to great lengths to compress that set of pixels so as to have it decompress to the very same "mere facsimile".

This is to say that JPG to PNG conversion never makes sense: since the PNG clearly can't conjure up out of thin air data that the JPEG compression discarded the quality can not ever improve in a visual sense; the PNG losslessly compressed a set of pixels that JPEG had already discarded information from. PNG vs. JPG is in that sense the same as e.g. FLAC vs. MP3; conversion from former to latter makes sense; from latter to former not.

Note; "mere facsimile" in quotes since JPEG is indeed in fact pretty good at what it does (and as far as human visual perception goes). As is PNG, but what it does is pretty fundamentally different in that lossless vs lossy sense.
User avatar
wallyUSA
Level 6
Level 6
Posts: 1140
Joined: Thu Jun 08, 2017 2:31 pm
Location: Top of Georgia

Re: Converting Jpeg to Png resulting in bloated file size

Post by wallyUSA »

@rene,
Excellent description :!:
Mint 20.2 Cinnamon 5.0.5 Kernel 5.4.0-86 {Dell XPS 13}

> If your query has been resolved, edit your original post and add <SOLVED> to the beginning of the subject line. This may help others find solutions. <
Hoser Rob
Level 17
Level 17
Posts: 7676
Joined: Sat Dec 15, 2012 8:57 am

Re: Converting Jpeg to Png resulting in bloated file size

Post by Hoser Rob »

FOSSguy_1x wrote:
Thu Aug 19, 2021 7:18 am
I was going to put this in the software section but I found out that it is not limited to the default "Image Viewer" application that comes with Linux mint.....
That doesn't matter.
FOSSguy_1x
Level 1
Level 1
Posts: 30
Joined: Thu Jan 28, 2021 3:50 pm

Re: Converting Jpeg to Png resulting in bloated file size

Post by FOSSguy_1x »

It is not by my design but Retroarch and Lakka OS which is a front-end for Emulation of Video Games require thumbnail images to be in a PNG format. RetroPie on the other hand accepts both jpeg and PNG.
vanadium
Level 3
Level 3
Posts: 111
Joined: Sun Dec 27, 2015 1:07 pm

Re: Converting Jpeg to Png resulting in bloated file size

Post by vanadium »

rene explained this perfectly. If you need to convert a jpeg to png for a particular reason, then, of cause, do it by all means. However, expect indeed a much increased file size: at least you know why this happens.

A case where png will win over jpeg is line graphics, i.e. line drawing or graphs with sharp lines and white space. png can compress that to very small sizes because of all the redundancy in such images, whereas jpeg will quickly reveal visual artefacts on that type of images.
User avatar
absque fenestris
Level 11
Level 11
Posts: 3583
Joined: Sat Nov 12, 2016 8:42 pm
Location: Confoederatio Helvetica

Re: Converting Jpeg to Png resulting in bloated file size

Post by absque fenestris »

After all, this question is about thumbnails.
You can apply Posterization to JPGs in GIMP, that is, reduce the colors.
As exported PNGs, the images are still far larger than the source JPG, but somewhat less drastically.
Linux Mint 18.3 Sylvia (MATE) 32-bit - Acer D250 Netbook
Linux Mint 20.0 Ulyana (Cinnamon) - Huawei MateBook X Pro
rene
Level 18
Level 18
Posts: 8083
Joined: Sun Mar 27, 2016 6:58 pm

Re: Converting Jpeg to Png resulting in bloated file size

Post by rene »

Not disagreeing with the above, but would still like to note that a (very) secondary lossy compression step in JPEG already is discarding of colour granularity; the colours you eventually see in in a JPG is what the program that originally generated said JPG decided was already as far as it was willing to go lest visual differences from the original would be too significant. That is, if posterization in that sense makes a significant difference in filesize I'd expect it to also do visually since that which didn't was already discarded.

Something like Retroarch seems likely to draw close attention from IP-trolls and I'd expect that missing JPG support is due to patent FUD even if only since I can't think of another reason. It seems a bit silly that it wouldn't just support JPG directly --- but given it doesn't you're really best off trying to find a PNG source so that you wouldn't have to convert at least.
FOSSguy_1x
Level 1
Level 1
Posts: 30
Joined: Thu Jan 28, 2021 3:50 pm

Re: Converting Jpeg to Png resulting in bloated file size

Post by FOSSguy_1x »

I found this software called YOGA Image Optimizer

It's not perfect but I had to manage by also resizing some of the images smaller. Sometimes it saves a bit of space by a small amount but it counts when you have so many thumbnails for video game playlist on Retroarch.

Results from a 720 x 977 (378.1 Kb file size)Jpeg image conversion to png I noticed with larger images is that even if it was that small in file size it can be significantly bigger when it is converted to a PNG file, I have seen some result in a file size above 4 Mb.

Results
Pix = 1.6 Mb
YOGA = 1.4 Mb


While I have scaled down larger images in GIMP another problem arose from that is that depending on how much I scaled down the image there will be a blurred image.
Sinnis250
Level 3
Level 3
Posts: 101
Joined: Thu Jun 16, 2016 9:47 am

Re: Converting Jpeg to Png resulting in bloated file size

Post by Sinnis250 »

FOSSguy_1x wrote:
Thu Aug 19, 2021 7:18 am
Any tips or programs I can use instead?
I would use jpegoptim from the Mint Software Manager. Its a command line programme but very efficient and simple to use.

As long as you have the path to the file to enter into the terminal you will find that a simple command will both convert and reduce the file size to whatever takes your fancy.

To put it simply, a 2mb file will be reduced to 1mb (approximately)with the use of this command.........

Code: Select all

jpegoptim --size=50% /home/yourmachinename/Desktop/100_9143.JPG
I find that the quality drops off at 25%, but I'm not too fussy.

There is a small article here.....
https://www.tecmint.com/optimize-and-co ... mmandline/

Running jpegoptim --help gives a whole stack of other commands and of course you can resize all your pictures in your directory in one go.

The resulting images will be jpegs using jpegoptim, but, much smaller files.

The easiest alternative I can suggest to actually make a png from a jpeg is by taking a capture/screenshot of it.

If you are going to play around with jpegoptim, make some backup copies of your pictures before committing yourself to using it.

:D
User avatar
wallyUSA
Level 6
Level 6
Posts: 1140
Joined: Thu Jun 08, 2017 2:31 pm
Location: Top of Georgia

Re: Converting Jpeg to Png resulting in bloated file size

Post by wallyUSA »

@FOSSguy_1x:

I do not remember where I found this but from the command line I can convert & resize at once using this command:

Code: Select all

convert bigshot.png -resize 50% smallshot.jpg
HTH
Mint 20.2 Cinnamon 5.0.5 Kernel 5.4.0-86 {Dell XPS 13}

> If your query has been resolved, edit your original post and add <SOLVED> to the beginning of the subject line. This may help others find solutions. <
Sinnis250
Level 3
Level 3
Posts: 101
Joined: Thu Jun 16, 2016 9:47 am

Re: Converting Jpeg to Png resulting in bloated file size

Post by Sinnis250 »

Having re-read your question again.......thumbnails??

A further addition; if you wish to extract a "thumbnail" from your picture/jpeg, you can go down the exif2 route.

The resulting filesize of a 2.8mb jpeg is reduced to 3.4kb.....which is recognisable, but f-ugly.

Install exif2 from the terminal using

Code: Select all

sudo apt install exiv2
Place your jpeg on the desktop (just for example) and convert/extract with the command, thus.......

Code: Select all

exiv2 -et /home/yourmachinename/Desktop/100_7579.JPG thumbnail
Resulting in a tiny picture and also keeping the original intact.

Hope this helps.

:D
TheyLive
Level 2
Level 2
Posts: 71
Joined: Wed Jun 03, 2020 1:47 pm
Contact:

Re: Converting Jpeg to Png resulting in bloated file size

Post by TheyLive »

FOSSguy_1x
I prefer Krita.
Select "Save As" - "png"
You can select compression
Attachments
Screenshot from 2021-09-12 20-49-36.png
Screenshot from 2021-09-12 20-49-36.png (25.46 KiB) Viewed 179 times
Goodly Mint - Best Firefox addon for this forum
viewtopic.php?f=211&t=340039
cday
Level 3
Level 3
Posts: 161
Joined: Mon Dec 02, 2019 12:18 pm
Location: Cheltenham, U.K.

Re: Converting Jpeg to Png resulting in bloated file size

Post by cday »

The point of reducing filesize by reducing the pixel dimensions of the thumbnail, whether using a GUI software, command line utility or by making a screenshot of the displayed image has been made, I think.

But it might be worth mentioning that for some image types, such as simple graphics with a limited number of colours, a PNG image can be both substantially smaller and also higher quality than a JPEG image.
Post Reply