Categories
- Ajax (1)
- Bisdak Blogger (1)
- chicks (1)
- Coffee and Paste (1)
- css (5)
- Excel (1)
- General Info (5)
- HTML (1)
- javascript (7)
- more (8)
- MySQL (1)
- pdf (1)
- Photoshop (1)
- PHP (26)
- SEO (1)
- sports (2)
Blog Archive
-
►
2009
(37)
-
►
March
(13)
- strlen vs isset in PHP
- 40 Tips for optimizing your php code
- $HTTP_SERVER_VARS
- Cross browser compatibility test site
- Detecting Mobile Browsers in PHP
- Passing JavaScript variables to PHP
- single-quote( ' ) vs double-quote ( " ) in PHP
- PHP Arrays
- Advantages of Using Functions
- Differences between constants and variables
- $_GET vs $_POST in PHP Forms
- require() vs include() in PHP
- What does !important mean in CSS?
-
►
February
(12)
- Javascript onclick return false does not work in I...
- Coffeeandpase Blogger: A Heavy Downloader
- Where is php.ini?
- Make a face
- Turn your photo into a cartoon
- Retrieving Japanese Text from MySQL using PHP
- CSS Play: Experiments with CSS
- New Online MD5 Hash Cracker!
- PNG Alpha Transparency Fix in IE
- Blogger.com as a website instead of a blog?
- Email address validation using Javascript
- PHPMailer: SMTP Authentication
-
►
March
(13)
-
▼
2008
(14)
-
▼
December
(8)
- Simple php pagination
- Create Image Thumbnails Using PHP and GD
- How to create a dynamic bar graph using PHP and GD...
- How to create a dynamic line graph using PHP and G...
- Simple PHP Image Watermark
- Manny Pacquiao vs Oscar De la Hoya (The Dream Matc...
- Live free streaming!!! Pacquiao vs. De La Hoya
- Javascript equivalent for PHP Functions
-
▼
December
(8)
Blog Roll
- Monkeetech
- Atenean101
- Batangsaag.blogspot.com
- Batangyagit.com
- Bethelo
- beyond-the-norms.org
- Brightartclass.blogspot.com
- Bugits
- Cebu Directories
- Cebudaily.com
- CebuElection
- Cebuheritage.com
- Cebuimage.blogspot.com
- Cebupacificairlines.ph
- Codes Depot
- Dahonglaya.com
- Empressofdrac
- Errol Duazo
- EUTS
- Iamdownloader.com
- Ibeejing
- Icymartagimacruz
- Ie-student
- In-indie.org
- Jerry Gervacio
- Lagahit.com
- Marian Calago
- Marroxas2010
- Mcbilly.com
- Miongandmarquee
- Nurseter
- Pinoyworld.org
- Punkies07
- QueerChef
- rentale
- Sinjin.ph
- softwareportables
- Sunchoke.net
- VeganPrince
- Vera
- Veryducky
- Yugatech
Create Image Thumbnails Using PHP and GD
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.. Some says that the only drawback to using PHP for image creation is that the thumbnails don’t look as good as thumbnails created in Photoshop or GIMP but this simple block of code would prove them wrong...
<?php
header ("Content-type: image/jpeg");
$image = $_GET['img'];
$w = 100; //default width if $w is not set
$h = 125; //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 image_thumb.php.
Usage:
<--without specifying the width and height-->
<img src="http://www.example.com/image_thumb.php?img=example.jpg" />
<--with height and width-->
<img src="http://www.example.com/image_thumb.php?img=example.jpg&w=200&h=200" />
This entry was posted on Friday, December 12, 2008
and is filed under
PHP
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.



1 comments:
learning PHp...aahhheheh!
Post a Comment