hi all
this is my script which creates one thumbnail from uploaded image
But now instead of one thumbnail
i want to generate 3 different size thumbnails
200×200
500×500
800×800
how to generate them ??
[code]
<?php chmod(‘images/’, 0777);
require_once(“functions.php”);
require_once(“path.php”);
if(isset($_FILES[‘prod_image’]))
{
if(preg_match(‘/[.](jpg)|(pjpeg)|(gif)|(png)$/’,
$_FILES[‘prod_image’][‘name’]))
{
$path=$_FILES[‘prod_image’][‘name’];
$filename = $_FILES[‘prod_image’][‘name’];
$source = $_FILES[‘prod_image’][‘tmp_name’];
$target = $path_to_image_directory . $filename;
move_uploaded_file($source, $target);
createThumbnail($filename);
}
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>
<body>
<form action=”” method=”post” enctype=”multipart/form-data” name=”form1″
id=”form1″>
<input name=”prod_image” type=”file” id=”prod_image” size=”60″ /> <br /><br
/>
<input type=”submit” value=”upload” name=”submit” />
</form>
</body>
</html>
this is functions.php
[code]
<?
function createThumbnail($filename) {
require ‘path.php’;
if(preg_match(‘/[.](jpg)$/’, $filename)) {
$im = imagecreatefromjpeg($path_to_image_directory . $filename);
} else if (preg_match(‘/[.](gif)$/’, $filename)) {
$im = imagecreatefromgif($path_to_image_directory . $filename);
} else if (preg_match(‘/[.](png)$/’, $filename)) {
$im = imagecreatefrompng($path_to_image_directory . $filename);
}
$ox = imagesx($im);
$oy = imagesy($im);
$nx = $final_width_of_image;
$ny = floor($oy * ($final_width_of_image / $ox));
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresampled($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);
if(!file_exists($path_to_thumbs_directory)) {
if(!mkdir($path_to_thumbs_directory)) {
die(“There was a problem. Please try again!”);
}
}
imagejpeg($nm, $path_to_thumbs_directory . $filename,70);
$tn = ‘<img src=”‘ . $path_to_thumbs_directory . $filename . ‘”
alt=”image” />’;
$tn .= ‘<br />Congratulations. Your file has been successfully uploaded, and
a thumbnail has been created.’;
echo “<p align=center>”. $tn . “</p>”;
}
?>
this is path.php
[code]
<?
$final_width_of_image = 200;
$path_to_image_directory = ‘images/’;
$path_to_thumbs_directory = ‘images/thumbs/’;
?>