JPG - PNG conversion problem

  • Thread starter Raaijmakers, Vincent \(GE Infrastructure\)
  • Start date
R

Raaijmakers, Vincent \(GE Infrastructure\)

Who can explain the huge increase in size when I convert a JPG into a PNG format using PythonMagick:
I read the JPG from a video server and has a resolution of 352x240, size is about 15k
After my PNG conversion and resizing the resolution to 160*120, the size is 64k!!

This is what I do:

##image = jpg data read from a server with a 352x240 resolution

blob = Blob()
blob.data = str(image)

data_len="jpg length data: %s" % len(blob.data)
logger.info(data_len) ## size is about 15k

## convert blob data into a Image
img = Image(blob)
img.depth = 8
img.magick = "PNG"
s = "!%sx%s" % (160, 120)
img.sample(s)

# convert back into data for streaming purposes
blob = Blob()
img.write(blob)

data_len="png length data: %s" % len(blob.data)
logger.info(data_len) ## size now 64k?!


what is wrong, or what do I forget to do? Is it the direct conversion from JPG to PNG,
do I need to add a step in between to RGB...
Also, tried to play with quality settings on the image, compressionTypes... nothing seem to help.

Needs advice!

thanks in advance,
Vincent
 
J

Jason Harper

Raaijmakers said:
Who can explain the huge increase in size when I convert a JPG into a PNG format using PythonMagick:
I read the JPG from a video server and has a resolution of 352x240, size is about 15k
After my PNG conversion and resizing the resolution to 160*120, the size is 64k!!

JPEG is a lossy compression format (well, normally - there are some
obscure exceptions to this). It throws away subtle details (details
that the human eye is relatively insensitive to) in order to achieve its
high compression ratios.

PNG uses only lossless compression. You are guaranteed that the image
you get out will be pixel-for-pixel identical to the image you put in.
Unfortunately, this greatly limits the possibilities for compression -
in fact, no lossless compressor can guarantee ANY reduction in file size
over all possible inputs.

Basically, converting a lossy to a lossless format gives you worst of
both worlds - the loss of detail of one, and the large file size of the other.
Jason Harper
 
M

Mark Borgerding

Raaijmakers said:
Who can explain the huge increase in size when I convert a JPG into a PNG format using PythonMagick:
I read the JPG from a video server and has a resolution of 352x240, size is about 15k
After my PNG conversion and resizing the resolution to 160*120, the size is 64k!!


Is the output png a color palette image? See if you can get acceptable
results by limiting the color palette to 256 colors or so.
 
F

Frantisek Fuka

Mark said:
Is the output png a color palette image? See if you can get acceptable
results by limiting the color palette to 256 colors or so.

The problem (although it's hard to call this "problem") is that PNG is
losless format, whereas JPG is not. What you are doing is akin to
converting JPGs to BMP or TIF.
 
D

Dietrich Epp

The problem (although it's hard to call this "problem") is that PNG is
losless format, whereas JPG is not. What you are doing is akin to
converting JPGs to BMP or TIF.

Er, BMP is uncompressed, PNG is compressed losslessly, TIFF can be
compressed a few different ways. Many TIFFs contain JPEG-compressed
data (which is why TIFF is such a cool format).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top