FruitNotes beta
Your All-in-One Online Notebook
FruitNotes Blogs | Home  
sample code to resize images in php using Image_Transform pear package
Last updated at (Fri Jan 04 2008 19:03:43)
Posted by: Nitin Gupta
0%




1) first thing would be to install pear package
for image transform
2) look into this package download and install


3) look into the example code towards the end, it uses this lib to do the image transformation

just change the image sizes and play with it.
e.g change 80, 80 to say 100, 120 in following
transformImg($path, $directory.'/new/'.$file, 80, 80);

to run it use on command prompt or call it via some url
php imgTrns.php

4) Put some images in $directory and you will see new images of modified width and height

 

Example code : save file as imgTrns.php

================


include_once 'Image/Transform.php';

$directory = "../images/gifts";
$directory_list = opendir($directory);

// and scan through the items inside
while (FALSE !== ($file = readdir($directory_list)))
{
// if the filepointer is not the current directory
// or the parent directory
if($file != '.' && $file != '..')
{
// we build the new path to scan
$path = $directory.'/'.$file;
if(stripos($file, 'icon')!==false)
{
transformImg($path, $directory.'/new/'.$file, 80, 80);
}
else
{
transformImg($path, $directory.'/new/'.$file, 400, 400);
}
}
}

function transformImg($src, $dest, $wt, $ht)
{
  $image = Image_Transform::factory('GD');
  if (PEAR::isError($image))
  {
   echo "Upload error1: " . $image->getMessage()."<br/>".$image->getDebugInfo();
   exit;
  }

  $imgFile = $image->load($src);
  if (PEAR::isError($imgFile))
  {
   echo "Upload error2: " . $imgFile->getMessage()."<br/>".$imgFile->getDebugInfo();
  }
  else
  {
    $image->fit($wt, $ht);
    $image->save($dest);
  }
}
?>

===========


Rate this blog

   Report Abuse


Comments


From Adi Adi at Fri Jan 21 2005 22:36:45 GMT 0500 (Pakistan Standard Time)

The earliest stone tools were crude, internet phone service being little more than a fractured rock. In the Acheulian era, beginning approximately 1.65 million years ago, methods of working these stone into specific shapes, such as hand axes emerged. The Middle Paleolithic, approximately 300,000 years merchant account ago, saw the introduction of the prepared-core technique, where multiple blades could be rapidly formed from a single core stone.[18] The high speed internet service Upper Paleolithic, beginning approximately 40,000 years ago, saw the introduction of pressure flaking, where a wood, bone, or antler punch could be used to hard drive recovery shape a stone very finely.[20]

-----------

Leave your comment(s) below:
To start Your own Blog




Other Blogs
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
» 
2007 FruitNotes.com - All Rights Reserved.