tags:

views:

30

answers:

1

Hello,

This is nice code. But it is uncertain. I am trying with jpg to gif conversion. With some images it reduces the size and with some images it increase the size.

Can you help me that how can i get the reduced sized gif from jpg.

Thanks, ravi

+1  A: 

JPG and GIF are fundamentally different formats, and most images that compress well in the one won't in the other.

In very short and massively, massively simplified - JPG's main method of compression is removing and simplifying subtle nuances invisible (or almost invisible) to the human eye, thus reducing image size.

This method is especially useful for photographs because they usually contain a lot of such subtle nuances, and very little totally homogeneous areas.

GIF's main compression method is to reduce data by detecting streaks of identical colours, and compressing the information, so

red red red red red red red green green green red red red 

becomes

7x red 3x green 3x red

this is known as Run Length Encoding.

obviously, this method is not suitable for photographs because usually, every pixel will have a slightly different colour value.

Therefore, photographic images can rarely be compressed well in GIF.

Why do you want to switch in the first place?

Pekka
Thanks for support,Actually I want to convert jpg file to gif and also need to reduce the size of the file then original jpg image.I m stucked from 2 days but not able to get any code to solve my purpose. Can you give me any suggestion to perform the task??I have tried Imagemagick code too but nothing happen.Thanks,ravi
Ravi
@Ravi well, as I said, that is not always possible. Can you show an example image?
Pekka
If you want to reduce the file size, then this is probably best achieved by reducing the pixel dimensions and/or lowering the quality of the image (quality is a JPEG term, it is the inverse of compression). Converting to GIF isn't going to do a good job unless the image lends itself to GIF format in the first place, and you clean up artifacts in the image as part of the process.
David Dorward
Yes Pekka... that is the issue with me... I have to keep the image height and width same. My issue is only with the size.. Yes you are true that if we change the dimension the size reduces but it change the original image.. I do not want like this....I am trying with some file reducing code... Ravi
Ravi
@Ravi you can't convert a photographic image into a GIF file and expect it to be as small as the JPEG version. It simply isn't possible. What do you need this for?
Pekka
http://www.business-trader.com.au/devsite/jpgtogif/sea.jpgSee here is my jpg image. I am writting a code to convert jpg image to gif on the fly and also trying to reduce the newly created file size as compare to existing jpg image.
Ravi
I have a existing folder of images on my server.The images are in thousands of numbers.so they are taking lots of space on my server.So to save the server space is one need.also the gif files loads fast. this is another need.
Ravi
@Ravi this is humbug. *You cannot convert such an image into GIF in a space-efficient way.* It is simply impossible for the reasons outlined in my answer. Also, the notion that GIF files load faster is not correct. File size determines loading speed. JPEG is the way to go here.
Pekka
So I need your suggession pekka. What should I do now? How can I fulfill my needs?
Ravi
I dont want to loose any image from my server. Should I have to resize my existing jpg images again to reduce the weight?
Ravi
@Ravi looking at the image you uploaded as an example. 25 kilobytes is perfectly all right a size for a JPEG that complex in my opinion. Why do you need to reduce image size in the first place? How many images do you have?
Pekka