creating thumbnails
Posted: Sun May 14, 2006 1:22 pm
how can I create thumbnails for .jpg and .png files?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$destimg = imagecreatetruecolor ($newWidth, $newHeight)
or die ("Problem In Creating image"); // Create thumbnail canvas
// Use one or use conditional to select i.e. if JPEG
$srcimg = imagecreatefromjpeg ("path to full sized")
or die ("Problem In opening Source Image"); // For JPEG
// else PNG
$srcimg = imagecreatefrompng ("path to full sized")
or die ("Problem In opening Source Image"); // For PNG
imagecopyresampled ($destimg, $srcimg, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height)
or die ("Problem In resizing"); // Resample the image from $srcimg to the $destimg
// Use one or use conditional to select i.e. if JPEG
imagejpeg ($destimg, "path to thumb") or die("Problem In saving"); // Save JPG
// else PNG
imagepng ($destimg, "path to thumb") or die("Problem In saving"); // Save PNGCode: Select all
<?php
$destimg = imagecreatetruecolor (250, 250)
or die ("Problem In Creating image"); // Create thumbnail canvas
// Use one or use conditional to select i.e. if JPEG
$srcimg = imagecreatefromjpeg ("uploads/boo.jpg")
or die ("Problem In opening Source Image"); // For JPEG
imagecopyresampled ($destimg, $srcimg, 0, 0, 0, 0, 250, 250, 494, 733)
or die ("Problem In resizing"); // Resample the image from $srcimg to the $destimg
// Use one or use conditional to select i.e. if JPEG
imagejpeg ($destimg, "uploads/tester.jpg") or die("Problem In saving"); // Save JPG
?>Code: Select all
<?php
$destimg = imagecreatetruecolor (250, 250)
or die ("Problem In Creating image"); // Create thumbnail canvas
// Use one or use conditional to select i.e. if JPEG
$srcimg = imagecreatefromjpeg ("./uploads/boo.jpg")
or die ("Problem In opening Source Image"); // For JPEG
imagecopyresampled ($destimg, $srcimg, 0, 0, 0, 0, 250, 250, 494, 733)
or die ("Problem In resizing"); // Resample the image from $srcimg to the $destimg
// Use one or use conditional to select i.e. if JPEG
imagejpeg ($destimg, "./uploads/tester.jpg") or die("Problem In saving"); // Save JPG
?>Code: Select all
list ($width, $height) = getimagesize("./uploads/boo.jpg");
// $width file width
// $height file heightAs always: The beauty lies in the eye of the beholderpsychotomus wrote:yes... what should i thumbnail them to?
Code: Select all
$loc = $row['id'] + 1;
if (move_uploaded_file($_FILES["file"]["tmp_name"], "./wallpapers/" . $loc . '.jpg'))
{
//SAVE THUMBNAIL
$srcimg = imagecreatefromjpeg ("./wallpapers/" . $loc . '.jpg')
or die ("Problem In opening Source Image"); // For JPEG
imagecopyresampled ($destimg, $srcimg, 0, 0, 0, 0, 150, 150, imagesx($srcimg) , imagesy($srcimg))
or die ("Problem In resizing"); // Resample the image from $srcimg to the $destimg
imagejpeg ($destimg, "./wallpapers_thumbs/" . $loc . ".jpg") or die("Problem In saving"); // Save JPGNice code. First time I've seen "list" used well.$phpNut wrote:and your not thumbnailing them to a square are you? ie distorting images and generally making them look horribleCode: Select all
list ($width, $height) = getimagesize("./uploads/boo.jpg"); // $width file width // $height file height
use http://phpthumb.sourceforge.net/.psychotomus wrote:how can I create thumbnails for .jpg and .png files?