Rectangle 27 4

Since PNG uses lossless data compression, the only way to achieve a decent compression in a PNG image (edge cases apart) is to save it as palette (rather than true colour) and reduce the number of colours. You appear to be processing some sort of screenshots. You may obtain smaller file sizes is you use a lossy compression, i.e., save as JPEG. In either cases, you reduce both file size and picture quality. You could also try the GIF format, which tends to be smaller for small graphs.

Last but not least, you should compress images once (typically when they get uploaded), not every time they're served. I suppose your code is just a quick test but I mention just in case.

I'm not familiar with PHP image functions but you should probably use a combination of imagecreatefrompng() and imagejpeg(). Also, consider whether you need to keep the original PNG for future reference or you can discard it.

Thanks Alvaro for the good pointers - It did'nt occur to me to save them originally in jpg or gif format - right now there is a flash webcam recorder that records the video and creates a snapshot image into a directory from where I'm reading to display in the browser - I might have to do a proper fix and see how the image is being saved initially rather than compressing it everytime as @Chochenos also suggested the same approach - Thanks

Please look at my edited question where i've posted the code that is saving the png file

Thanks Alvaro - I was able to use the functions you mentioned to create a jpg file which brought down the size way down. But right now I have a 2 step process - Step 1) using file_put_content - generate the image. Step 2) Using imagecreatefrompng and imagejpeg compress the image. Also there is no requirement for me to hold onto the original png file. So I will need a 3rd step to delete that file. So this three step process - is it the best way to go about it - thanks

I have updated the question to include your suggested way of generating the jpg file - Thanks

php compressing images showing varying results - Stack Overflow

php
Rectangle 27 0

Different images have different compressions. With JPEG you sacrifice quality for smaller size and with PNG 24 you get alpha transparency. What you're probably more interested in is getting the smallest size image possible for the format you're using. There are 2 good command line tools for handling this. You kind of have to play around with different types, programs like photoshop make it really easy to see which is smallest. Once you've found your optimum format you can use a "smusher" to remove extraneous data that isn't needed by the image but often gets added by the editor. Below are 2 command line utilities I uses to make sure my images are as small s possible when building websites, but are also beneficial for any application.

both can be installed easily using homebrew: http://mxcl.github.com/homebrew/ and I'd assume theres an option for macports as well.

There also C-based so either can be used in an iOS project.

ios - Most smallest lossless image format and/or library? - Stack Over...

ios optimization image-compression
Rectangle 27 0

Old browsers like IE6 (which is now deprecated) don't support transparent PNG files, so it really depends on which browsers you plan to support. In general, PNG files are fine and will run on all major browsers. Unlike JPEGs, PNG is lossless and this may work against it at times when compressing. If the image is complex, it may be better to have it saved as a JPEG for better quality. There's a small table here which briefly explains each format. A tool I use for really compressing PNGs files is PNG Monster. This often gets a better compression than some graphics applications.

Exactly I just downloaded omg I compressed 6 png files it did very good job without lowering the quality of the picture awesome ! Thanks Bytes before: 23956 Bytes after: 6463

image - Is PNG bad for Browser Compatibility - Stack Overflow

image png cross-browser
Rectangle 27 0

It looks like you are getting JPEG image format with compression inside your FLA, not PNG. And to avoid that, you need to specify that your image compression should be lossless. You can do that in library or in MovieClip props.

I have one more idea: those artefacts could appear because of scaling (not necessarily of those images, may be parent is scaled).

Thank you for the idea, but this is not the case. I import images and place them into root timeline. Flash shows no scaling on images and there are no parent containers.

graphics - PNG with transparency from Photoshop to Flash: how to make ...

flash graphics png photoshop alpha-transparency
Rectangle 27 0

If you want to optimise JPEG, I'd go for http://jpegmini.com

If you want to step out of JPEG and PNG you could try Google's WebP (http://code.google.com/speed/webp/) but I have no idea if there are any iOS libraries for it and if they are whether they are any good.

ios - Most smallest lossless image format and/or library? - Stack Over...

ios optimization image-compression
Rectangle 27 0

PNG format is a lossless compression file format, which makes it a common choice for use on the Web. PNG is a good choice for storing line drawings, text, and iconic graphics at a small file size.

Portable Network Graphics is a lossless file format created with the intent to replace the GIF format, due to the patent restrictions of GIF compression. The project was a success and we now have complete access to the format, which is patent-free, has great compression, and is widely supported by web browsers. PNG files are used primarily for transparent images, simple-color images, and images that have hard lines, like text. There are two versions of PNG files: 8-bit PNG(known as PNG-8) and 24-bit PNG(known as PNG-24). PNG-8 is limited to 256 indexed colors, while PNG-24 has millions.

Joint Photographic Experts Group created a file format, creatively named JPEG \j-peg\, to handle complex-color photographic images. When saving a file as a JPEG, users have the choice of quality vs. compression. More compression results in a smaller file size, but you will lose quality. Obviously, less compression results in a larger file-size, but also a higher-quality image. The great thing about JPEG compression is that you can usually find a balance that both looks good and has a small file size. Unfortunately, JPEG files have no transparency. Additionally, the file format is lossy, meaning that it loses some of its data each time it is compressed. If you re-save the same image multiple times for some reason, the image quality may be low.

JPG format is a lossy compressed file format. This makes it useful for storing photographs at a smaller size than a BMP. JPG is a common choice for use on the Web because it is compressed. For storing line drawings, text, and iconic graphics at a smaller file size, GIF or PNG are better choices because they are lossless.

JPEGs are for photographs and realistic images. PNGs are for line art, text-heavy images, and images with few colors. GIFs are just fail.

so why the png presentaion of image will bigger than the image 's rawdata size ?

JPEG and PNG use completely different compression methods. JPEG uses a DCT-based lossy compression method that sacrifices quality in favor of smaller file sizes. PNG prioritizes quality and uses the lossless DEFLATE compression algorithm. JPEG's file size can be cut down by adjusting an image's quality percentage during saving, while PNG's file size is less easily adjusted and usually requires a separate program to further compress the image. check this - diffen.com/difference/JPEG_vs_PNG

is there any way to get a uiimage object's raw data content length ?because UIImagePNGRepresentation or UIImageJPEGRepresentation is not working correctly

ios - why the UIImagePNGRepresentation return larger data than (10 tim...

ios uiimage sdwebimage
Rectangle 27 0

Since PNG uses lossless data compression, the only way to achieve a decent compression in a PNG image (edge cases apart) is to save it as palette (rather than true colour) and reduce the number of colours. You appear to be processing some sort of screenshots. You may obtain smaller file sizes is you use a lossy compression, i.e., save as JPEG. In either cases, you reduce both file size and picture quality. You could also try the GIF format, which tends to be smaller for small graphs.

Last but not least, you should compress images once (typically when they get uploaded), not every time they're served. I suppose your code is just a quick test but I mention just in case.

I'm not familiar with PHP image functions but you should probably use a combination of imagecreatefrompng() and imagejpeg(). Also, consider whether you need to keep the original PNG for future reference or you can discard it.

Thanks Alvaro for the good pointers - It did'nt occur to me to save them originally in jpg or gif format - right now there is a flash webcam recorder that records the video and creates a snapshot image into a directory from where I'm reading to display in the browser - I might have to do a proper fix and see how the image is being saved initially rather than compressing it everytime as @Chochenos also suggested the same approach - Thanks

Please look at my edited question where i've posted the code that is saving the png file

Thanks Alvaro - I was able to use the functions you mentioned to create a jpg file which brought down the size way down. But right now I have a 2 step process - Step 1) using file_put_content - generate the image. Step 2) Using imagecreatefrompng and imagejpeg compress the image. Also there is no requirement for me to hold onto the original png file. So I will need a 3rd step to delete that file. So this three step process - is it the best way to go about it - thanks

I have updated the question to include your suggested way of generating the jpg file - Thanks

php compressing images showing varying results - Stack Overflow

php
Rectangle 27 0

It looks like you are getting JPEG image format with compression inside your FLA, not PNG. And to avoid that, you need to specify that your image compression should be lossless. You can do that in library or in MovieClip props.

I have one more idea: those artefacts could appear because of scaling (not necessarily of those images, may be parent is scaled).

Thank you for the idea, but this is not the case. I import images and place them into root timeline. Flash shows no scaling on images and there are no parent containers.

graphics - PNG with transparency from Photoshop to Flash: how to make ...

flash graphics png photoshop alpha-transparency
Rectangle 27 0

If I'm interpreting your question correctly, you'll already need to look at the file format defined in JPEG2000 Part 2 ("JPX") because of the multiple bands. Beyond that, because you are asking for "visually lossless" (e.g. lossy compression but tuned to the point where you can't see it), you'll need to experiment with various settings using your own files until you achieve what you want. For a small discussion on how the Internet Archive did this with print materials, see A Status Report on JPEG 2000 Implementation for Still Images: The UConn Survey.

Thanks for the answer. Well, probably I should have given more details. I wanted to know which would be the best software to do this compression. WE tried ArcGIS and it is taking unusally long time - for 25 gb it took almost 2 days+; same with ERDAS. The hardware configuration is reasonable. Do you think just upgrading to speed up will help or is there any other better way of going about it?

Hmmm -- that seems unusually long. I'm most familiar with the Kakadu Software implementation, and it comes with a "speed pack" to support higher speed requirements. You might try looking at that; good luck!

compression - Compressing High Resolution Satellite Images - Stack Ove...

compression image jpeg2000 satellite
Rectangle 27 0

You're on the wrong track with this. Saving a bitmap object requires Image.Save(). That's a method that knows how to use an image encoder to convert a bitmap into the bytes that another program (or yours) can load back. There are several image encoders, you can select the one you want with the Save() overload that lets you pick the ImageFormat. The BMP format is the native Windows format, it is uncompressed. The PNG format is nice, it is a compressed lossless format. The JPEG format is a compressed lossy format, good for photos. File size is big to small in order.

c# - File.WriteAllBytes or FileStream.Write - Stack Overflow

c# stream filestream
Rectangle 27 0

You can save the images in whatever format is most appropriate for your needs: this will probably be either JPG or PNG. The former is smaller, but lossy, the latter is lossless. So if image quality is extremely important to you, use PNG. If not, I'd use JPGs (which will have the added advantage of using up less space on disk).

You're currently not saving any of your images to disk, just keeping them around in memory in an array, and that's what's causing you problems. You could handle this in a number of ways, depending on what you want your app to do. Do you need to save your images to disk? If so, maybe set a limit on the number of images allowed in memory at any one time and dump them to disk when required. Or perhaps you're just doing some analysis on the images, in which case you can just release them when you no longer require them.

Thanks lxt. So, do you mean I should change the type in which I keep the images in the array to NSData using "NSData *UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality);"?

ios - AVCaptureSession didReceiveMemoryWarning - Stack Overflow

ios uiimage format avcapturesession didreceivememorywarning
Rectangle 27 0

It is the function setImageCompressionQuality to set the compression level that is done for PNG images. As PNG is a lossless image format, this does not affect the actual image quality (like it does for JPEG images) instead it just tells the library how much effort, and which strategy to use when compressing the images. The code below runs through all of the possible options.

pngcrush -brute Original.png pngcrushBrute.png

Original.png: 192,382 bytes - Without setting any specific compression level FullColor92.png: 181,832 bytes - the best output from all the possible options. pngcrushBrute.png: 178,129 bytes - which is probably more due to removing extra headers than that much better compression.

$imagick->setImageFormat('jpg');
$imagick->setImageCompressionQuality(80);
  • Imagick/ImageMagick already gets close to the best compression with the default settings.
  • If you need to get the best compression, then using PngCrush will give a slightly better result than Imagick can.
  • If the image is a photo, serve it as a jpg. It it's a diagram/must be served with a png, you could try color reduction, which would give good 'compression' but isn't suitable for photos, as it looks crap.
//10's digit:
//
//        0 or omitted: Use Z_HUFFMAN_ONLY strategy with the
//           zlib default compression level
//
//        1-9: the zlib compression level
//
//     1's digit:
//
//        0-4: the PNG filter method
//
//        5:   libpng adaptive filtering if compression level > 5
//             libpng filter type "none" if compression level <= 5
//or if image is grayscale or palette
//
//        6:   libpng adaptive filtering
//
//        7:   "LOCO" filtering (intrapixel differing) if writing
//a MNG, otherwise "none".  Did not work in IM-6.7.0-9
//and earlier because of a missing "else".
//
//8:   Z_RLE strategy (or Z_HUFFMAN_ONLY if quality < 10), adaptive
//             filtering. Unused prior to IM-6.7.0-10, was same as 6
//
//        9:   Z_RLE strategy (or Z_HUFFMAN_ONLY if quality < 10), no PNG filters
//             Unused prior to IM-6.7.0-10, was same as 6

$imagick = new Imagick("./Biter_500.jpg");

$imagick->setImageFormat('png');

$imagick->writeimage("./output/original.png");
compressAllTypes($imagick, "./output/FullColor");


function compressAllTypes(Imagick $imagick, $filename) {
    for ($compression = 0; $compression <= 9; $compression++) {
        echo "Compression $compression \n";
        for ($filter = 0; $filter <= 9; $filter++) {
            echo "Filter $filter";
            $output = clone $imagick;
            $output->setImageFormat('png');
            //$output->setOption('png:format', 'png8');
            $compressionType = intval($compression . $filter);
            $output->setImageCompressionQuality($compressionType);
            $outputName = $filename."$compression$filter.png";
            $output->writeImage($outputName);
        }
        echo "\n";
    }
}

Imagick PNG compression in PHP - Stack Overflow

php compression imagick