Click here to Skip to main content
15,909,586 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I want to compress the size of jpeg images that I am using on my website, I want C# code for this. I dont want to use tools and Handlers to do it.
Posted
Updated 17-Feb-16 18:34pm
v2
Comments
[no name] 29-Sep-12 14:45pm    
Did you want to reduce size of your user's profile image?

1) Why don't you take a gander at some of these code project articles:
http://www.codeproject.com/search.aspx?q=image+compression&x=5&y=9&sbo=qa[^]

2) "Does it compress image size". Of course. What would be the point to compression if no compression takes place?
 
Share this answer
 
v2
You want to compress a lossy jpeg again with a lossless compression? Well, you will probably not succeed. Why? Because by definition a lossy compression will be able to compress better in general, than a lossless, since it will loose information details. So, even if the jpg compressed image itself is new set of data, and has it's own structure, you will get a bigger file in general after the second compression, or at least not smaller. In really special cases you can get smaller file at the end.
You better try to find the most suitable compression ration (quality factor) for your files. In general 65-75% is good for web page images.
 
Share this answer
 
Comments
hardiksince1987 29-Sep-12 18:59pm    
I might have to go with 75% of the quality level. I am doing this to improve my performance grade. I am checking performance using http://gtmetrix.com. It always shows that the Image could be losslessly compressed upto 30%(more or less depending on Image). I looking for solution if you have any let me know.
Zoltán Zörgő 30-Sep-12 6:12am    
It depend of your images and image sizes. It is up to you and your needs. Be aware, that not every quantilizer is as efficient as the other, thus you might get smaller file under the same conditions with Photoshop for example as with Paint (just examples). Notice also, that lossless formats like png are better for generated graphics (like charts), and jpg is better for photos. You can also make use of deferred download of images (see: http://www.appelsiini.net/projects/lazyload). If your images are not static context (not stored and server from a static folder), you can use the Etag to optimize caching.
And finally, you can fine-tune caching to minimize download traffic.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900