You are here: Thumbnail orientation « PHP Programming Language « IT news, forums, messages
Thumbnail orientation

Posted by Milagro on 05/03/07 14:28

Hi,

I'm using the code below to create thumbnails from photos. The code
works fine and thumbnails are created. However, thumbnails of vertical
photos are oriented as horizontal photos.

More info:
These photos come from a Nikon high end SLR digital camera. It's not my
camera so I have no control over how the image is taken.
If I open a vertical image in Photoshop (CS2), the image is oriented
correctly. When I try to create a thumbnail with php, the thumbnail is
always oriented incorrectly as Horizontal.
I did some further testing and tried opening the same image using
ImageMagic (on a Linux box). ImageMagic also sees the image incorrectly
as Horizontal.

There has to be some way to read the JPG file and determine if it's
meant to be a vertical or horizontal photograph. Are there any php
libraries that are capable of doing this?

Does anyone know the layout of a JPG binary well enough to tell me if
there is a specific flag set for orientation?

Thanks for all of your suggestions.

M



<?

$fname="verttest.jpg";
$fname2="Thumb_verttest.jpg";
$thumbWidth="300";


echo "Creating thumbnail for $fname";


// load image and get image size
$img = imagecreatefromjpeg($fname);
$width = imagesx( $img );
$height = imagesy( $img );


echo "\n";
echo "Current Width:" . $width;
echo "\n";
echo "Current Height:" . $height;
echo "\n";

// calculate thumbnail size
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );

echo "\n";
echo "New Width:" . $new_width;
echo "\n";
echo "New Height:" . $new_height;
echo "\n";

// create a new temporary image
$tmp_img = imagecreatetruecolor( $new_width, $new_height );

// copy and resize old image into new image
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width,
$new_height, $width, $height );

// save thumbnail into a file
imagejpeg( $tmp_img, "{$pathToThumbs}{$fname2}" );
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация