4

I am working in asp.net webapi. I have 30 to 40 images in my resource folder. Is there anyway I could compress my images programatically instead of manually, resizing the images in resources?

John Conde
  • 217,595
  • 99
  • 455
  • 496
Sadda-shutu
  • 1,309
  • 2
  • 18
  • 42
  • 3
    There's a difference between resizing images and compressing images. Which one are you trying to achieve? Or both? Also please provide more details about your API. How is it going to be used? What methods does it expose? How are the images being accessed? Your question doesn't make much sense at the moment. – Darin Dimitrov Sep 24 '12 at 12:06
  • actually i am new for webapi here i need to compress a images in my application folder i have 40 images now i wana to know how to compress this images by writing hard code mr.Darin Dimitrov could u provide me some idea about it i am using mvc4 thank you for reply i dont know what to do – Sadda-shutu Sep 24 '12 at 12:14
  • Why do you want to compress images? Normally images if stored using compression algorithms such as JPEG, PNG, GIF, ... they are already compressed. What further compression do you want? It would be perfectly useless to apply ZIP compression to say a JPEG image. Are you trying to use CSS sprites or something? I really don't understand what your problem is and what does the Web API has to do with it. – Darin Dimitrov Sep 24 '12 at 12:16
  • yes right mr.Darin Dimitrov but here i need to load images myself images will have more bytes in sizes and i need load it and optimize the images may by optimize it will reduce file size and reflect same quality like that i need to load image and optimize it for increase loading page perfomance – Sadda-shutu Sep 24 '12 at 12:21
  • i mean i need to optimize images by writing hard code – Sadda-shutu Sep 24 '12 at 12:22
  • I really don't understand what you are talking about. I am sorry. Maybe it's the language barrier that's preventing me from understanding. Hopefully someone else will understand your question and be able to answer it. – Darin Dimitrov Sep 24 '12 at 12:22
  • i wil explain you here i am working on mvc4 now i am taking some i mages in my folder (solution explore(folder(images)))riht – Sadda-shutu Sep 24 '12 at 12:24
  • now i need to optimize those images when i call those images i will come with real size i need to optimize those like we are providing size is't possible r not i dont know – Sadda-shutu Sep 24 '12 at 12:27
  • @DarinDimitrov I have no idea what he's trying to do either. What kind of images are you talking about? What format do they have? – magnattic Sep 24 '12 at 12:38
  • .png and .jpg images we are loading – Sadda-shutu Sep 24 '12 at 12:46
  • look this site in this optimizing u will get the idea the images look result in this site http://imageoptimizer.codeplex.com/ here we have a option to this but i need to this type of optimization by writing the hard code – Sadda-shutu Sep 24 '12 at 12:49
  • 1
    Like Darin's comment above, if you are loading PNG and JPEG images, there is no need for compressing them any further. It will in fact harm the size. From what I understand in your comments, you are looking to speed up the loading of the page by reducing the total size of the ~40 images, and you don't want to manually resize them (which is the first option you should consider). Using [CSS sprites](http://css-tricks.com/css-sprites/) might help a bit in this regard; they will reduce the number of http requests. This has nothing to do with MVC or WebAPI specifically. – pleinolijf Sep 24 '12 at 14:03
  • yes u r right mr.pleinolijf exactly that;s what i need no need to do in mvc let me try this thank you for your reply – Sadda-shutu Sep 24 '12 at 14:20
  • possible duplicate of [ASP.NET Image uploading with Resizing](http://stackoverflow.com/questions/254419/asp-net-image-uploading-with-resizing) – Servy Sep 25 '12 at 20:22

1 Answers1

1

If you're talking about resizing images, there are plenty of tutorials on the Internet, and a good answer on SO:

ASP.NET Image uploading with Resizing

Community
  • 1
  • 1
RemarkLima
  • 11,639
  • 7
  • 37
  • 56