Re: Why small > big?

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

 



Alex:

Excuse for top posting:

You said: Clear as mud?

Well actually, it's simperer than I thought. After your reply, I did some reading on jpeg and found it's simply a transform, not unlike FFT where two-dimensional temporal data is transformed from the time domain to the frequency domain -- very interesting reading.

The reverse cosine matrix you mention is probably the discrete cosine transform (DCT) matrix where the x, y pixels of an image file have a z component representing color. From that you can translate the data into the frequency domain, which actually generates more data than the original.

However, the quality setting is where you make it back up in compression ratio's by trimming off higher frequencies which don't add much to the data. Unlike the FFT, the algorithm does not address phasing, which I found interesting.

However, the answer to my question deals with the quality statement. In the statement:

imagejpeg($image_p, null, 100);

I should have used something less than 100.

I've change the figure to 25 and don't see any noticeable difference in quality of the thumbnail.

It seems to me there should be a table (or algorithm) somewhere that would recommend what quality to use when reducing the size of an image via this method. In this case, I reduced an image 62 percent (38% of the original) with a quality setting of 25 and "see" no difference. I think this (the quality factor) is programmable.

As for png images, I would probably agree (if I saw comparisons), but not all browsers accept them. I belive that at least one IE has problems with png's, right?

tedd

At 4:45 PM +0100 8/23/06, Alex Turner wrote:
M Sokolewice got it nearly correct. However, the situation is a little more complex than he has discussed.

The % compression figure for jpeg is translated into the amount of information stored in the reverse cosine matrix. The size of the compressed file is not proportional to the % you set in the compressor. Thus 100% actually means store all the information in the reverse cosine matrix. This is like storing the image in a 24 bit png, but with the compressor turned off. So at 100% jpeg is quite inefficient.

The other issue is the amount of high frequency information in your images. If you have a 2000x2000 image with most of the image dynamics at a 10 pixel frequency, and you reduce this to 200x200 then the JPEG compression algorithm will 'see' approximately the same amount of information in the image :-( The reality is not quite as simple as this because of the way JPEG uses blocks etc, but it is an easy way of thinking about it.

What all this means is that as you reduce the size of an image, if you want it to retain some of the detail of the original but at a smaller size, there will be a point at which 8 or 24 bit PNG will become a better bet.

Clear as mud?

AJ

M. Sokolewicz wrote:
I'm not quite sure, but consider the following:

Considering the fact that most JPEG images are stored with some form of compression usually ~75% that would mean the original image, in actual size, is about 1.33x bigger than it appears in filesize. When you make a thumbnail, you limit the amount of pixels, but you are setting compression to 100% (besides that, you also use a truecolor pallete which adds to its size). So, for images which are scaled down less than 25% (actually this will prob. be more around 30-ish, due to palette differences) you'll actually see the thumbnail being bigger in *filesize* than the original (though smaller in memory-size)

- tul

P.S. isn't error_reporting( FATAL | ERROR | WARNING ); supposed to be error_reporting( E_FATAL | E_ERROR | E_WARNING ); ??

tedd wrote:
Hi gang:

I have a thumbnail script, which does what it is supposed to do. However, the thumbnail image generated is larger than the original image, how can that be?

Here's the script working:

http://xn--ovg.com/thickbox

And, here's the script:

<?php /* thumb from file */

/* some settings */
ignore_user_abort();
set_time_limit( 0 );
error_reporting( FATAL | ERROR | WARNING );

/* security check */
ini_set( 'register_globals', '0' );

/* start buffered output */
ob_start();

/* some checks */
if ( ! isset( $_GET['s'] ) ) die( 'Source image not specified' );

$filename = $_GET['s'];

// Set a maximum height and width
$width = 200;
$height = 200;

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

if ($width && ($width_orig < $height_orig))
    {
    $width = ($height / $height_orig) * $width_orig;
    }
else
    {
    $height = ($width / $width_orig) * $height_orig;
    }

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

//  Output & Content type
header('Content-type: image/jpeg');
imagejpeg($image_p, null, 100);

/* end buffered output */
ob_end_flush();
?>

---

Thanks in advance for any comments, suggestions or answers.

tedd


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


--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.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