Re: Convert from jpg to gif ... change dpi...[off something]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-TG:

I apologize for my sarcasm.

Let's start at basic "Images 101", shall we? Please be opened minded enough to consider.

The original poster simply asked:

Is there any way of converting a jpg to gif and change dpi on the fly?

We both agree that we can change the image from a jpg to a gif, that's obvious.

What we disagree about is IF the dpi of the image can be changed, right?

Okay, so what is a dpi of a image? Where do find dpi in the image file and how does that relate to the dpi of the display of the image?

A jpg file is nothing more than a header followed by a collection of samples. NOTE, samples are not dots per inch, but instead they are pixels -- they are simply samples of an image (PICture ELement).

Yes, in the header of a jpp file you will find:

  BYTE Units;           /* 09h  Units used for Resolution */
  BYTE Xdensity[2];     /* 0Ah  Horizontal Resolution     */
  BYTE Ydensity[2];     /* 0Ch  Vertical Resolution       */
  BYTE XThumbnail;      /* 0Eh  Horizontal Pixel Count    */
  BYTE YThumbnail;      /* 0Fh  Vertical Pixel Count      */

But, what you are failing to understand is that this is the method of capture, and not of subsequent display. There is nothing you can do to this file to change how it was obtained -- and -- regardless of what you did, you could not force the image to be restricted to a specific dpi. The only thing you can do is to change the number of samples in the image (excepting changing aspect ratio, filtering/changing the depth of the sample, and such).

Certainly, the unit for resolution can be inches or cm (dpi or dpc), but that's for capture. The horizontal and vertical resolutions are for aspect ratios, such as 1:1, not for dpi -- and the pixel counts here are simply the number of samples in the jpg file.

Sure, camera manufacturers typically talk about megapixels, but that's a simply the maximum capacity of the camera to capture samples. However, the way they use the term "pixel" is a bit misleading when it comes to display and printing. There has always been confusion as to what to do with the image for printing. Have you ever tried to print a megapixel picture?

Certainly you can take a megapixel picture and print it on a megapixel printer and get a picture, but that does not mean that the dpi noted in the header had anything to do with your setting the resolution of the picture to the printer.

For example, an image that has 100 samples by 100 samples simply means it has 10,000 samples. Now, you could have captured the samples by a variety of means, namely camera, PhotoShop, scanner, or whatever.

Certainly, the resolution (dpi) of the device is a consideration for capturing the image. For example, you can scan a 5 inch by 5 inch piece of artwork (25 square inches) at any number of resolutions to gather as many samples as you want. If you set the resolution of your scanner to 100 dpi, then your image will have 25 x 100 x 100 samples (25,000 samples). But note, that is not the same as 100 dpi because dpi isn't in the equation yet because we haven't displayed the image!

If you use Photoshop and set the resolution of your artwork to 100 dpi and print the 5 inch square artwork, then you should see the original image at it's proper size. But, if you print it at 50 dpi, you'll see the image at 25 percent -- in other words, 2.5 inches square. The DPI isn't in the image, it's in your settings.

However, if you show the artwork on your monitor, it's "size" (the actual size) will depend upon your monitor settings and the ability of your monitor to show images.

A pixel is a pixel, some will say, but how the computer uses the pixel to display things is an entirely different matter.

For example, let's look at how different systems display standard text.

We all know, or should know, that text sizes (outside of a computer) are based upon a point system.

I won't go back to the history and development of the point from 1737 to today, but the end result was that the "American pica" measures 0.1660 inches -- just under one sixth of an inch (often called a pica point), which is a tiny bit less than 1/72 of an inch.

Now, I won't go back to the Apple ][ days either -- however -- we did work with pixel and point sizes back then in our very limited High Res memory block for graphics.

By time Apple developed the Mac (before PC's of similar vein), they were well aware and wanted to make their graphic monitors as close as possible to the printed word. As such, they chose 72 pixels per inch. If you will note, the "WYSIWYG" phrase was coined by Mac long before PC's -- not bragging, just fact.

When the PC's followed, for whatever their reason (I think it had something to do with VESA and VGA specifications for monitors, or cost), M$ chose 96 pixels per inch.

So, in terms of raw pixels, most Windows user see text that's about 33 percent larger than the same text as seen on a Mac and the same thing goes for anything that's dependant upon pixels. That's the reason why most Window-made web sites look tiny on a Mac.

Unfortunately, because of Mac's minor, yet strong grasp, of 3 percent of the market, the remaining 97 percent is forcing Mac to change their WYSIWYG standards. The dpi (or ppi) thing in Mac's now depends upon what system you are using, which includes 72, 85, 90, 93, and 110 dpi.

So, if you want to see graphics at whatever resolution you want, you can do that provided that the image has enough samples -- not dpi.

If you have a Mac with a resolution of 72 dpi, display an image at 72 dpi, and then drop that image to a printer at 72 dpi, it will measure exactly on your monitor as it does on the printed page. That's a fact, I do it all the time. If you can't do it, then buy a Mac.

Furthermore, if you extend the display of the graphic beyond it's number of samples, then the image program (like Photoshop) will interpolate between known samples (pixels) and you'll see the image degrade. This is not because the dpi in the image is not matching the pixels on the monitor, but rather the number of samples are not sufficient to met display demands.

So jgs, like most images are nothing more than a set of samples. The depth of the sample may change (number of colors it can represent), the compression of the images (lossless, lossy) may be different, and the size of the image may change, but in the end they are nothing more than samples. It's how the samples are displayed that determines the dpi and not the samples themselves.

Now do you understand?

tedd

---

At 2:55 PM -0400 5/8/06, <tg-php@xxxxxxxxxxxxxxxxxxxxxx> wrote:
First, a correction or clarification to what I was saying. PPI and DPI are not the same. PPI is used for on-screen display, DPI is used for printing. The quick and dirty with DPI is that printers can print dots, but each dot represents only (typically) the standard CMYK (cyan, magenta, yellow, black) colors.. so if you have a 600 PPI image and print it with a 600 DPI printer, you're not going to get an exact representation. One source recommended a 1200 dpi printer for 300ppi images (1200dpi / 4 possible colors per dot = 300 ppi effective printing? dunno.. it seems not exactly correct somehow but think that's what their rationale was).

 What you are doing in Photoshop is simply changing the number of...

Wow.. what a great jumble of words you got here. Let's bullet it:

* ..simply changing number of samples
* You are not changing the DPI of the image..
* .. still show the image in any dpi you want, you just change
  the ability of the image to retain it's quality over a
  larger range of dpi..

What is a 'sample' to you/

Yes I am changing the dpi/ppi of the image as indicated by the "pixels per inch" next to the setting I'm changing.

And finally..

huh?? Yeah, of course a higher ppi image is going to retain it's quality when you blow it up. I'm really not sure what this paragraph is saying but it doesn't seem to address any argument or make any point other than saying "No.. you're wrong".

 Surprise, surprise -- why is that? GIF's were developed for web pages...

Why the contradictory tone? All you did was re-state what I said.. but in a tone that seems antagonistic... kinda funny actually.. just don't know where you're going with that.

 72 ppi on-screen vs 72 dpi on printer

Yeah.. as I stated (and it makes some kind of sense even if the 300ppi -> 1200dpi thing might not be totally true), a 72 ppi image on screen printed on a 72dpi printer is NOT going to look exactly like it will on-screen.. even if 72 ppi matched 72 dpi (assuming each printer dot could do a full 256, 32k, or more colors..which it cant) it's still a 72 dpi image. So it's going to be bigger and pretty clunky looking. If you moved the piece of paper away from you til the image was about the same size (to you) as the one the screen, it'd probably look pretty much the same.. assuming you had a printer that could match the color variation per dot as your computer was displaying per pixel... which they don't.

This next part is my favorite...

 jpeg faq links
 You will not find any mention of dpi. Why? Because DPI is not
 relevant to the image...it only pertains to the display of the image.

How is dpi or ppi not relevant to the image? So are you saying that programs like Photoshop and devices like printers just 'invent' or conjure up some magic numbers and use those for dpi and ppi when they're displaying or printing? GIFs and older image file formats may not bother to store that information because it's just known that GIFs are 72ppi. That's just a hard fact. Hell, maybe GIF89a or something may have provisions for storing ppi info... but not that I've seen. PNG came around as a freeware replacement for GIF and I'm sure it has ppi information in them... as do jpeg files. Here's a faq link of my own for ya:

http://www.fileformat.info/format/jpeg/

Notice the part right up top about the file header data:

typedef struct _JFIFHeader
{
  BYTE SOI[2];          /* 00h  Start of Image Marker     */
  BYTE APP0[2];         /* 02h  Application Use Marker    */
  BYTE Length[2];       /* 04h  Length of APP0 Field      */
  BYTE Identifier[5];   /* 06h  "JFIF" (zero terminated) Id String */
  BYTE Version[2];      /* 07h  JFIF Format Revision      */
  BYTE Units;           /* 09h  Units used for Resolution */
  BYTE Xdensity[2];     /* 0Ah  Horizontal Resolution     */
  BYTE Ydensity[2];     /* 0Ch  Vertical Resolution       */
  BYTE XThumbnail;      /* 0Eh  Horizontal Pixel Count    */
  BYTE YThumbnail;      /* 0Fh  Vertical Pixel Count      */
} JFIFHEAD;

horizontal resolution, vertical resolution, units used for resolution.

"Units, Xdensity, and Ydensity identify the unit of measurement used to describe the image resolution. Units may be 01h for dots per inch, 02h for dots per centimeter, or 00h for none (use measurement as pixel aspect ratio)."

What do ya know? DPI... or.. for the rest of the non U.S. world.. DPCM. Guess DPI information is stored within the jpeg format after all.

 You will not find any mention of dpi. Why?

Because the faqs you pointed to decided not to mention it... not because it doesn't exist.

 Go ask a chicken what "eggs per package" it's egg will be put in, a
 dozen, a dozen and a half, two dozen, or what? Eggs, like pixels,
 haven't friggen a clue as to what packing they're going to be put in.

Beautiful. *applaud* I have no adequate response to this that I feel will do any good at untangling the logic presented.

So... back to PHP and more rational discussions?

-TG

= = = Original message = = =

-TG:

At 10:51 AM -0400 5/8/06, <tg-php@xxxxxxxxxxxxxxxxxxxxxx> wrote:
Actually I don't believe this is exactly right....  from playing
around with Photoshop you can see that you change an image's
resolution under Image -> Image Size and if you turn off "Resample
Image", it will retain the same pixel dimensions.

What you are doing in Photoshop is simply changing the number of
samples in the image. You are not changing the dpi of the image. In
fact, you can still show the image in any dpi you want, you just
changed the ability of the image to retain it's quality over a larger
range of dpi, nothing more.


GIF's are limited to 72dpi (or ppi if you prefer.. pixel per inch)
which matches what is typically displayable or desirable for web
content.  But when you go to print that webpage, you really see the
 >lack of quality in that GIF image.

Surprise, surprise -- why is that?

GIF's were developed for web pages and the typical monitor was 72 dpi
(now, they vary greatly).

When you take a GIF and print it, you now have a different medium at
which to view the image. If you can set your printer to 72 dpi, and
your monitor to 72 dpi, then you'll see very little difference
between the monitor image and the printer image. However there are
some differences in the way a monitor and paper shows an image
(brightness and so on).

If you use a JPG and set it for around 300 dpi/ppi, it prints out a LOT nicer.

Yes, and if you have images that are capable of 2880 dpi, and you
print them at 2880 dpi, they will look even better, but so what?

You have missed the point. Outside of some newer cameras that embed
capture information into the headers of the image file, jpg's do not
have dpi information in them. I suggest you read:

http://www.faqs.org/faqs/jpeg-faq/part1/
http://www.faqs.org/faqs/jpeg-faq/part2/

You will not find any mention of dpi. Why? Because DPI is not
relevant to the image -- it only pertains to the display of the image.

Go ask a chicken what "eggs per package" it's egg will be put in, a
dozen, a dozen and a half, two dozen, or what? Eggs, like pixels,
haven't friggen a clue as to what packing they're going to be put in.

Again, DPI is a way to display an image and is not something
intrinsic within the image itself.

tedd


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
--------------------------------------------------------------------------------
http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux