Create thumbnail using php and gd library
The following PHP code will create thumbnail images on the fly and since it uses the PHP GD2 library, you will need an installation of PHP with at least GD 2.0.1 enabled.. This is a very simple script and very easy to customise.
<?php
header (“Content-type: image/jpeg”);
$image = $_GET['thumimg'];
$w = 110; //default width if $w is not set
$h = 135; //default height if $h is not set
} $x = @getimagesize($image);// get image size
$sw = $x[0];// width
$sh = $x[1];// height
$im = @ImageCreateFromJPEG ($image) or // Read JPEG Image
$im = false; // If image is not JPEG
if (!$im)
readfile($image);// return the actual message if error occurs.
else {
// Create the resized image destination
$thumb = @ImageCreateTrueColor ($w, $h);
// Copy from image source, resize it, and paste to image destination
@ImageCopyResampled ($thumb, $im, 0, 0, 0, 0, $w, $h, $sw, $sh);
// Output resized image
@ImageJPEG ($thumb);
}
?> save the above code as thumbimg.php.
<–without specifying the width and height–>
<img src=”http://www.mysite.com/thumbimg.php?thumimg=example.jpg” />
<–with height and width–>
<img src=”http://www.mysitee.com/thumbimg.php?thumimg=example.jpg&w=100&h=100″ />
Related posts:
- Water mark images using PHP 5 and GD Library
- Simple php watermark script
- BitDefender Antivirus
- How to create random passwords using php
