I'm trying to use mogrify to decrease the quality of the image to ultimately decrease the image size but rather than decreasing it, the image size is increasing. I'm using the following command:
mogrify -quality 20% 1.png
The image size is going from 2.5 mb to 4 mb, any idea?
PNG is a lossless format, so changing "quality" settings should do nothing at all with respect to the "image".
The mogrify documentation confirms this - "quality", when applied to a PNG, indicates which row filters to apply: a value ranging from 0 to 6.
Since the input 20 is invalid for a PNG file, it must have been silently replaced with a default value; presumably 0, which indicates no row filtering at all. (If you really want to know if this is the case, you could use a tool such as pngcheck on your before and after images.)
As to your target: it is unclear whether you want to decrease the physical image size in pixels, or the file size on disk, or (possibly) both. For the first, you can use -resize. For the second, try a PNG-recompressing tool such as pngcrush. For both, use the first method and then the second.
Another option may be to lower the number of color components, for example, from 24-bit RGB to indexed color. Finally, you can always convert the image type from PNG to JPEG, after which you can experiment with the "quality" parameter.
Related
i've been using image magick for a while. and i've had it it just flood my ram too much for my use case which is usually just making animated gifs from a sequence of pngs or adjust the delay of an existing gif into another gif
i saw this alternative called graphics magick that's supposedly works the same way except its more optimized but the -delay flag doesn't seem to be doing anything no matter what number i put in there. from the docs it says its supposed to be 1/100 of a second so for a 60 fps gif it should be 1.6 which is the same for imagemagick. but it doesn't work it seems to just the use the default delay which is too long.
i'm on arch linux 6.0.6-arch1-1
and using the 1.3.38 version of graphicsmagick
here is the gif i'm trying to animate with a sequence of pngs with this script
/usr/bin/gm convert -delay 0.016 -loop 0 -dispose previous *png ../orc_barbers_with_graphics_magick.gif
here is the output
and this is the code i ran with image magick basically the same thing (thisone is the correct frame delay)
convert -delay 0.016 -loop 0 -dispose previous *png ../orc_barbers_2.gif
here is the output
the problem with me doing it this way is this took almost 10 mins to make while convert taking up 13 of my 16 gigs of ram
I am trying to save a bulk of image files after cropping them with cv2.IMWRITE_PNG_COMPRESSION, 9, but this is extremely slow. It takes about one hour for 5000 images.
cv2.imwrite(fn, img, [int(cv2.IMWRITE_PNG_COMPRESSION),9)
This is the command along with the path(fn), the image(img) and the compression mode, 9. If I use the default mode 3, that is by not giving the third argument the png's size gets doubled.
My qusetion is, Is there a way to optimize the process of compression, or any other library that can do this given that img has been opened using img = cv2.imread(src).
I am playing with image uploads to a website and I found out about these decompression bomb attacks that can take place when it's allowed to upload png files (and some other). Since I am going to change the uploaded images, I want to make sure I don't become a victim of this attack. So when it comes to checking if a png file is a bomb, can I just read the file's headers and make sure that width and height are not more than the set limit, like 4000x4000 or whatever? Is it a valid method? Or what is the better way to go?
Besides large width and height, decompression bombs can also have excessively large iCCP chunks, zTXt, chunks, and iTXt chunks. By default, libpng defends against those to some degree.
Your "imagemagick" tag indicates that you are you asking how to do it with ImageMagick. ImageMagick's default width and height limits are very large: "convert -list resource" says
Resource limits: Width: 214.7MP Height: 214.7MP Area: 8.135GP
Image width and height limits in ImageMagick come from the commandline "-limit" option, which I suppose can also be conveyed via some equivalent directive in the various ImageMagick APIs. ImageMagick inherits the limits on iCCP chunks, etc., from libpng.
Forged smaller width and height values in the IHDR chunk don't fool either libpng or ImageMagick. They just issue an "Extra compressed data" warning and skip the remainder of the IDAT data without decompressing it.
I'm tired to capture an image from GPUImageStillCamera and I got an image which has dimension 2592 X 1936 and 5.1 MB in size(and the image taken in iPad mini). This is too large(for my app). How to reduce the image dimension while capturing an image?
As I said in response to this GitHub issue you created, use -forceProcessingAtSize: on the first filter in your filter chain to lock it to a given size. If that size is larger than the default video size, you might want to do this right before you capture your photo, then set it back to 0 (using an unrestricted size) after the photo is captured.
I'v got a bitmap 24bits, I am writing application in c++, MFC,
I am using libjpeg for encoding the bitmap into jpeg file 24bits.
When this bitmap's width is M, and height is N.
How to estimate jpeg file size before saving it with certain quality factor N (0-100).
Is it possible to do this?
For example.
I want to implement a slide bar, which represent save a current bitmap with certain quality factor N.
A label is beside it. shows the approximate file size when decode the bitmap with this quality factor.
When user move the slide bar. He can have a approximate preview of the filesize of the tobe saved jpeg file.
In libjpeg, you can write a custom destination manager that doesn't actually call fwrite, but just counts the number of bytes written.
Start with the stdio destination manager in jdatadst.c, and have a look at the documentation in libjpeg.doc.
Your init_destination and term_destination methods will be very minimal (just alloc/dealloc), and your empty_output_buffer method will do the actual counting. Once you have completed the JPEG writing, you'll have to read the count value out of your custom structure. Make sure you do this before term_destination is called.
It also depends on the compression you are using and to be more specific how many bits per color pixel are you using.
The quality factor wont help you here as a quality factor of 100 can range (in most cases) from 6 bits per color pixel to ~10 bits per color pixel, maybe even more (Not sure).
so once you know that its really straight forward from there..
If you know the Sub Sampling Factor this can be estimated. That information comes from the start of frame marker.
In the same marker right before the width and height so is the bit depth.
If you let
int subSampleFactorH = 2, subSampleFactorV = 1;
Then
int totalImageBytes = (Image.Width / subSampleFactorH) * (Image.Height / subSampleFactorV);
Then you can also optionally add more bytes to account for container data also.
int totalBytes = totalImageBytes + someConstantOverhead;