hi SamA74
i will go with the proportional height at present while keeping width fixed.
but can you tell me how to create two thumbnails instead of one.
here is my working script which creates one thumbnail of 200 width only.
how can i create another thumbnail also with it of 500 width also
so that on every single image i get 2 thumbnails generated and uploaded of 200 and 500
<?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>
here is functions.php
<?
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>";
}
?>
path.php
<?
$final_width_of_image = 200;
$path_to_image_directory = 'images/';
$path_to_thumbs_directory = 'images/thumbs/';
?>