Basic question: Why are camera jpegs larger than GD repros?

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
woozy
Forum Newbie
Posts: 2
Joined: Sun Jan 27, 2008 9:24 pm

Basic question: Why are camera jpegs larger than GD repros?

Post by woozy »

Please forgive me if this has been asked answered or considered trivially basic but I'm very curious.

Why is a jpeg from my digital camera (7 gigapixels, 1.5 Mb) three times larger than an image resulting by copying it with GD.

For example, the following code:

$im = ImageCreateFromJPEG("file1.jpg");
$width = ImageSx($im);
$height = ImageSy($im);
ImageJPEG($new, "file2.jpg");

will open a 1.5 Mb jpeg file, gets its image data, and copies it into a new jpeg file only 449 kb in size.

I'm assuming, the jpeg display information of the first file only accounts for 1/3 the file's information and that the resulting jpeg still has every bit of display information as the first but that all the raw camera information was also stored in the first file but not copied to the second.

I'm I at all close?

I'm just curious but I'd like to knew if an image reproduced with GD is any "less" than the original. Also I'm am now very curious about what the heck is jpeg information anyway.

-cheers
woozy
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Basic question: Why are camera jpegs larger than GD repros?

Post by Kieran Huggins »

jpeg is a lossy format - it's likely that the compression on your camera is set very low to keep image quality high, but the default settings for the PHP function are much more aggressive.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Basic question: Why are camera jpegs larger than GD repros?

Post by s.dot »

Also, the exif data in the jpeg most likely contains a thumbnail image with a pretty decent size. Other comments and info in the exif data could take up significant room. That combined with kierans explanation makes a lot of sense.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply