useful function for you

Top Page
Author: PHP Web Development
To: phpug-ph, phphilippines, PHP Web Developers' Mailing List
CC: robert.oh
Subject: useful function for you
I was searching for a class that can generate thumbnails, most of them have inherent problems like some need imagemagik or netpbm, others use GD library that does not support gif files anymore.

Below is a function that auto resizes your images to the width and height that you want. its quite simple, i should be banging myself in the head not thinking of this sooner.


function resize_pic($w,$h,$img,$alt="",$click=""){
// resize_pic - PHP function
// This function resizes images into their correct proportion
// Copyright (C) 2004 Edson Ngo Pabiloña, Quantum X, Inc.
// License: Free, just dont remove this!

/* Input fields:
$w= required width
$h= required height
$img = image file
$alt= image description
$click= if there is a value, the image is clable, and opens to a new window at its full size
       echo resize_pic(100,100,"images/YourPictureHere.jpg","test picture",1);

  $tmp = @GetImageSize($img);// get image size
 if(!$tmp)return"";// if not an image, escape
 if($tmp[0]>=$tmp[1]){ // if width is greate than height 
      $h=$w*$tmp[1]/$tmp[0];// compute the proportional height
      $w=$h*$tmp[0]/$tmp[1];// compute the proportional width
  $width=abs($w);// there you go
  $height=abs($h);// there you go
 if($click){$a1="<a href='$img' target=_blank>";$a2="</a>";$c1=" - Click to Enlarge";}//if clickable, add anchors
 return"$a1<img src=\"$img\" height=\"{$height}\" width=\"{$width}\" border=0 alt='$alt $c1'>$a2";// return the image


Edson Ngo Pabiloña
Quantum X, Inc
19 Purdue St. North Greenhills
1500 San Juan, Philippines
Tel: 7251044; 7259447
Mobile: 0917-7915197
Email: edson.pabilona@???
Visit us at: http://www.quantumx.com______________________________________________
PHP Web Development Mailing List
php@??? (#PHP @
Searchable Archives: