Discussion:
Convert from jpg to gif ... change dpi...
Gustav Wiberg
2006-05-07 21:07:14 UTC
Permalink
Hi there!

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

Best regards
Gustav Wiberg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Rory Browne
2006-05-08 01:07:42 UTC
Permalink
imagemagick?
Post by Gustav Wiberg
Hi there!
Is there any way of converting a jpg to gif and change dpi on the fly?
Best regards
Gustav Wiberg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
tedd
2006-05-08 13:53:37 UTC
Permalink
Post by Gustav Wiberg
Hi there!
Is there any way of converting a jpg to gif and change dpi on the fly?
Best regards
Gustav Wiberg
Gustav:

It depends how big the fly is.

But seriously, yes you can change a jpg into a gif by loading it in
as a jpg (imagercreatefromjpeg) and then saving it as a gif
(imagegif).

See: http://www.weberdev.com/imagegif

But, the dpi thing is not meaningful. DPI is how the image is
displayed and not something intrinsic within the image itself. The
image has simply a size (x by y pixels), and how that image is
previewed is outside its purview (I liked that play on words) :-)

If you want to change the image's size, then that can be done via
magecopyresized. But, you cannot change the DPI of an image.

tedd
--
--------------------------------------------------------------------------------
http://sperling.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
t***@gryffyndevelopment.com
2006-05-08 14:51:13 UTC
Permalink
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.

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.

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


So there's a real easy answer to this question... yes, you can change DPI on the fly when converting JPG -> GIF... the downside is that you're converting to 72dpi whether you like it or not because that's the GIF standard.

If somebody has more or better information on this, I'd love to hear it but this is how it is as far as I know and have experienced.

-TG

= = = Original message = = =
Post by Gustav Wiberg
Hi there!
Is there any way of converting a jpg to gif and change dpi on the fly?
Best regards
Gustav Wiberg
Gustav:

It depends how big the fly is.

But seriously, yes you can change a jpg into a gif by loading it in
as a jpg (imagercreatefromjpeg) and then saving it as a gif
(imagegif).

See: http://www.weberdev.com/imagegif

But, the dpi thing is not meaningful. DPI is how the image is
displayed and not something intrinsic within the image itself. The
image has simply a size (x by y pixels), and how that image is
previewed is outside its purview (I liked that play on words) :-)

If you want to change the image's size, then that can be done via
magecopyresized. But, you cannot change the DPI of an image.

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
tedd
2006-05-08 17:32:49 UTC
Permalink
Post by t***@gryffyndevelopment.com
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.
Post by t***@gryffyndevelopment.com
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).
Post by t***@gryffyndevelopment.com
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

--previous --
Post by t***@gryffyndevelopment.com
So there's a real easy answer to this question... yes, you can
change DPI on the fly when converting JPG -> GIF... the downside is
that you're converting to 72dpi whether you like it or not because
that's the GIF standard.
If somebody has more or better information on this, I'd love to hear
it but this is how it is as far as I know and have experienced.
-TG
= = = Original message = = =
Post by Gustav Wiberg
Hi there!
Is there any way of converting a jpg to gif and change dpi on the fly?
Best regards
Gustav Wiberg
It depends how big the fly is.
But seriously, yes you can change a jpg into a gif by loading it in
as a jpg (imagercreatefromjpeg) and then saving it as a gif
(imagegif).
See: http://www.weberdev.com/imagegif
But, the dpi thing is not meaningful. DPI is how the image is
displayed and not something intrinsic within the image itself. The
image has simply a size (x by y pixels), and how that image is
previewed is outside its purview (I liked that play on words) :-)
If you want to change the image's size, then that can be done via
magecopyresized. But, you cannot change the DPI of an image.
tedd
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--
--------------------------------------------------------------------------------
http://sperling.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Porpoise
2006-05-09 20:01:54 UTC
Permalink
Post by t***@gryffyndevelopment.com
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.
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.
If you use a JPG and set it for around 300 dpi/ppi, it prints out a LOT nicer.
So there's a real easy answer to this question... yes, you can change DPI
on the fly when converting JPG -> GIF... the downside is that you're
converting to 72dpi whether you like it or not because that's the GIF
standard.
If somebody has more or better information on this, I'd love to hear it
but this is how it is as far as I know and have experienced.
Well, still a learner on the PHP front but as far as images are concerned,
just a bit more knowledgeable.

First off, DPI is not a function within an image, it is a function of output
and is governed by a combination of the programme doing the output and the
device it is being output to.

So, to make things clearer, let's take an actual example.

We have an image - we'll call it 'image_A' of size (in pixels) of 3000 x
2000. If you want to output that image to a printer (which has a resolution
of 300lpi) you will get an image size of 3000/300 x 2000/300 = 10 x 6.67
inches. But the image is still 3000 x 2000 pixels. If you want to output it
to a printer with 600lpi resolution then it will print an image size of
3000/600 x 2000/600 = 5 x 3.33 inches and still, the real image size is 3000
x 2000 pixels. However, if we look at it from the viewpoint of the
application (rather than the printer), we can see a slightly different
perspective on the same data: If we already know that the resolution of the
output device (in this case a printer) is 300lpi and we know that we want
the printed image to measure 10 x 6.67 inches then we can set the dpi within
the application (Photoshop or whatever, that, when it comes to print the
image, we want it to "tell" the printer to print the image at a resolution
of 300lpi. If we know that we want to print the image at a size of 5 x 3.33
inches (on that same 300lpi printer) then the application will know that the
output resolution to produce that image size *should* be 600lpi. However,
the printer is only 300lpi so what takes place is called interpolation where
2 pixels within the application is are output as 1 pixel to the printer.

However, monitors typically don't have anywhere near that resolution
(typically they are around 72 - 96 dpi) so that same 3000 x 2000 pixel image
is now going to a different output device (the monitor) at 96 dpi, so the
image size now output on-screen is 3000/96 x 2000/96 = 31.25 x 20.83
inches - which is way bigger than any current monitor (although you could,
perhaps, use multiple displays), so, in order for the image to display at a
reasonable size on screen, we need to reduce the image SIZE to take account
of the SCREEN dpi (96dpi). This means that for the image to display at a
size of 300 x 200 pixels on a screen (of resolution 96 dpi) we need to make
the image SIZE: 300 x 200 pixels. However, if we want to display the image
at a size on screen of, say, 6 inches x 4 inches, then we need to do the
calculation for the required image size: (6 x 96) x (4 x 96) = 576 x 384
pixels.

The screen resolution likewise is a function of the number of pixels (of the
screen) and the size (in inches) of the screen:

screen width: 1024 pixels - 13.2 inches; then dpi = 1024/13.2 = 77.5dpi
screen width: 1280 pixels - 13.2 inches; then dpi = 1280/13.2 = 96 dpi

etc.

So, in conclusion, the DPI of an image is an OUTPUT function - it is not
inherent to the actual image. However, you may see DPI data stored within
the metadata of a file, where it has been stored by the application used to
edit it, because the application has stored information you have given it to
communicate with (usually) the printer. It serves no other purpose.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
tedd
2006-05-09 20:45:34 UTC
Permalink
Post by t***@gryffyndevelopment.com
If somebody has more or better information on this, I'd love to hear
it but this is how it is as far as I know and have experienced.
First off, DPI is not a function within an image, it is a function
of output and is governed by a combination of the programme doing
the output and the device it is being output to.
-snip- (useful stuff)
So, in conclusion, the DPI of an image is an OUTPUT function - it
is not inherent to the actual image. However, you may see DPI data
stored within the metadata of a file, where it has been stored by
the application used to edit it, because the application has stored
information you have given it to communicate with (usually) the
printer. It serves no other purpose.
Thanks for your explanation. Anyone who agrees with me, must be very
intelligent. :-)

tedd
--
--------------------------------------------------------------------------------
http://sperling.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Porpoise
2006-05-09 22:42:34 UTC
Permalink
Post by tedd
Thanks for your explanation. Anyone who agrees with me, must be very
intelligent. :-)
IyamIyam..... ;-)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Richard Lynch
2006-05-08 17:52:13 UTC
Permalink
Post by Gustav Wiberg
Is there any way of converting a jpg to gif and change dpi on the fly?
<?php
$source = "/full/path/to/image.jpg";
$image = imagecreatefromjpeg($image);

//optional step, to REALLY trim that sucker down:
//cut this step out if it looks really bad.
//this gives you more control of what you call "change the DPI"
//GIF is already going to chop it down to 256 colors.
imagetruecolortopalette($image, FALSE, 16);

header("Content-type: image/gif");
imagegif($image);
?>
--
Like Music?
http://l-i-e.com/artists.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...