DJ Mike's Tutorials: PHP

Imagick Functions

^ >

Imagick::thumbnailImage

Description:
bool Imagick::thumbnailImage ( int $columns , int $rows [, bool $fit ] )

Changes the size of an image to the given dimensions and removes any associated profiles. The goal is to produce small low cost thumbnail images suited for display on the Web.
Parameters:
columns
Image width
rows
Image height
fit
Whether to force maximum values. If TRUE then columns and rows parameters are used as maximums for each side. Both sides will be scaled down until the match or are smaller than the parameter given for the side.
Return Values
Returns TRUE on success.
Errors/Exceptions
Throws ImagickException on error.

Example 1

<?php 
header
('Content-type: image/jpeg'); 
$image = new Imagick("opossum.jpg"); 
$image->thumbnailImage(500); 
echo 
$image
?>

Example 2

This example gets every .jpg in a directory, makes thumbnails for them and use the thumbnail to link to the full image. To use it copy the text file and change the extension to thumbs.php. In the page you want to have the thumbnails add this line of code:

<?php include("thumbs.php"); ?>


<?php
$width 
200# maximum width
$self $_SERVER[PHP_SELF];
# if image submitted then make thumbnail
if ( $im $_GET[im] )
 {
 
header('Content-type: image/jpeg'); 
 
$image = new Imagick("$im"); 
 
$image->thumbnailImage($width0); 
 echo 
$image;  
 exit;
 }
# find all .jpg's in current directory
foreach (glob("*.jpg") as $filename)
 {
  
# make image links 
  
echo "<a href=\"$filename\"><img src=\"$self?im=$filename\" width=\"$width\"></a>&nbsp;&nbsp;";
 }
?>
text

                                                                    


^ >

Was this webpage useful to you? You can support this website by donating.


Created by DJ Mike from Santa Barbara

DJ Mike


<a href="http://www.statcounter.com/" target="_blank"> <img src="http://c5.statcounter.com/counter.php?sc_project=1321035&java=0&security=da2193dc" alt="counter free hit invisible" border="0" /></a>