Not a Member Yet,
Click here to Register
How do you like the new design?






ID: 512
Viewed: 3692
Added: Sep 30, 2003
Version: 1
Snippet uploaded by: snippet
Written By: snippet
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

here is a short little script that will take an image and create a thumbnail view of the same image. this will not just resize it but it creates a new image and makes it the correct size so it actually leaves the default image alone.

Browsers: all
GD Library: 2.0+

<!---Head--->
none

<!---Body--->


 <?php 

$error = False;
$img_size = 20;
$image = "someimage.jpg";

// check if the 'image' parameter has been given
if (!isset($image)){ // if not generate an error
$error = True;
}
if(!$bigimage=@imagecreatefromjpeg($image)){
$error = true;
}

if($error){ // generate an error image
$img = ImageCreate(123, 100);
$bg = ImageColorAllocate($img, 255, 255, 255);
$white = ImageColorAllocate($img, 255, 0, 0);
ImageString($img, 5, 30, 20, "Picture", $white);
ImageString($img, 5, 45, 40, "Not", $white);
ImageString($img, 5, 25, 60, "Available", $white);
ImagePNG($img);
ImageDestroy($img);
exit();
}

$x=imageSX($bigimage);
$y=imageSY($bigimage);

if($resize == 'no' || (($x > $y) && ($x < $img_size)) || (($y > $x) && ($y < $img_size))){

imagejpeg($bigimage);
exit();
}

// find the larger dimension
if ($x>$y) { // if it is the width then
$dx = 0; // the left side of the new image
$w = $img_size; // the width of the new image
$h = ($y / $x) * $img_size; // the height of the new image
$dy = 0; // the top of the new image
} else { // if the height is larger then
$dy = 0; // the top of the new image
$h = $img_size; // the height of the new image
$w = ($x / $y) * $img_size; // the width of the new image
$dx = 0; // the left edgeof the new image
}

$thumbimage =ImageCreateTrueColor($w, $h);
ImageCopyResampled($thumbimage, $bigimage, $dx, $dy, 0, 0, $w, $h, $x, $y);

imagejpeg($tnimage);

// release the memory used by the thumbnail image
ImageDestroy($thumbimage);

// release the memory used by the original big image
ImageDestroy($bigimage);

?>


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 snippetlibrary.com All Rights Reserved. Conditions