This below mentioned code is written localhost/uploads/gallery.php file. I am including it in another page so it can be a part of header and footer including all my styling. I did it by include('uploads/gallery.php'); into a div.
Everything is working fine except the header location. When I go to the page where gallery is included which is "localhost/index.php?page=media"(localhost/views/media.php). It does not display thumbnails. I have to refresh the page to see thumbnails. Note: the code is written to display thumbnails when they are generated without refreshing the page.
My concern for asking question is, why i have to refresh page to load thumbnails. My header location is not passing variables correctly. I am a complete noob. please help me with this. Shukriya.
<?php
if(isset($_GET['img'])){
if(file_exists("uploads/{$_GET['img']}")) {
ignore_user_abort(true);
set_time_limit(120);
ini_set('memory_limit', '256M');
$src_image = getimagesize("uploads/{$_GET['img']}");
var_dump($src_image);
if($src_image === false) {
die("Wrong Image");
} # Wrong File Size
// Fixed Thumbnail Size
$thumb_width = 144;
$thumb_height = 144;
$thumb_ratio = round (($thumb_width / $thumb_height), 1);
$src_ratio = round (($src_image[0] / $src_image[1]), 1);
if ($src_ratio > $thumb_ratio) {
//Landescape Image dynamic width...
$new_size = array(($src_image[0] * $thumb_height)/$src_image[1], $thumb_height);
$new_pos = array(($new_size[0] - $thumb_width)/2,0);
} elseif ($src_ratio < $thumb_ratio) {
//PORTRAIT Image dynamic Height.....
$new_size = array($thumb_width, ($src_image[1] * $thumb_width)/$src_image[0]);
$new_pos = array(0, ($new_size[1] - $thumb_height)/2);
} elseif($src_ratio == $thumb_ratio) {
//Square
$new_size = array($thumb_width, $thumb_height);
$new_pos = array(0, 0);
}
if($new_size[0] < 1) $new_size[0] = 1;
if($new_size[1] < 1) $new_size[1] = 1;
$imgz = 'uploads/thumbs/'.$_GET['img'];
//GETTING Variable for Source image type. to create resample
if($src_image['mime'] === "image/jpeg"){
$src = imagecreatefromjpeg('uploads/'.$_GET['img']);
} elseif($src_image['mime'] === "image/png"){
$src = imagecreatefrompng('uploads/'.$_GET['img']);
} elseif($src_image['mime'] === "image/gif"){
$src = imagecreatefromgif('uploads/'.$_GET['img']);
}
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb, $src, 0,0, $new_pos[0], $new_pos[1], $new_size[0], $new_size[1], $src_image[0], $src_image[1]);
//GETTING Variable for Destination thumb image type. to create resample
if($src_image['mime'] === "image/jpeg"){
imagejpeg($thumb, $imgz);
} elseif($src_image['mime'] === "image/png"){
imagepng($thumb, $imgz);
} elseif($src_image['mime'] === "image/gif"){
imagegif($thumb, $imgz);
}
header("Location: uploads/thumbs/{$_GET['img']}");
} /* If file exists */ die();
} // ALL SCRIPT ENDED
if(is_dir('uploads/thumbs') === false) {
mkdir('uploads/thumbs', 0744);
} // Check & Create Directory
$images = glob('uploads/'.'*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE);
foreach($images as $image){
$imgs = 'uploads/thumbs/'.substr($image,8);
$nme = substr($image,8);
if(file_exists("$imgs")){
echo "<img src=\"$imgs\" alt=\"$nme\" class=\"img-thumbnail\" />"; //uploads/{$img} , data-toggle=\"modal\" data-target=\"#myModal\"
} else {
echo "<img src=\"?page=media&img=$nme\" alt=\"$nme\" class=\"img-thumbnail\" />";
}
}
?>
Related
I am trying to resize all frames of a gif and sometimes they turn out extremely weird.
I've seen examples using the command line and I would like to try and avoid this for now.
Original:
Resized:
You can see clearly the problem.
Now my code:
$imgBlob = file_get_contents(__DIR__ . '/../assets/test_gif.gif');
if ($imgBlob === false) {
echo 'img blob failed!' . PHP_EOL;
return;
}
$img = new Imagick();
$img->readImageBlob($imgBlob);
$img->coalesceImages();
$count = 0;
foreach ($img as $_img) {
// $_img->coalesceImages();
$imgWidth = $_img->getImageWidth();
$imgHeight = $_img->getImageHeight();
$ratio = $imgHeight / $imgWidth;
$resizeWidth = 200;
$resizeHeight = 300;
if ($ratio > 0) {
$resizeWidth = round($resizeHeight / $ratio, 0);
} else {
$resizeHeight = round($resizeWidth / $ratio, 0);
}
//if ($_img->adaptiveResizeImage($resizeWidth, $resizeHeight) === false) {
if ($_img->resizeImage($resizeWidth, $resizeHeight, Imagick::FILTER_CATROM, 1, 0) === false) {
echo 'FAILED' . PHP_EOL;
}
$count++;
}
$thumbnailOnDisk = __DIR__ . '/../assets/test_resized.gif';
if (file_exists($thumbnailOnDisk)) {
unlink($thumbnailOnDisk);
}
$img = $img->deconstructImages();
if ($count > 1) {
$file = $img->writeImages($thumbnailOnDisk, true);
} else {
$file = $img->writeImage($thumbnailOnDisk);
}
echo 'DONE' . PHP_EOL;
Not sure exactly what coalesceImages or deconstructImages is doing and I am having a hard time finding an example online that would fix my problem.
$img->coalesceImages();
Returns an imagick object, which I was discarding.
$img = $img->coalesceImages();
Works.
As you resize the image, you need to set size of image page as well.
http://php.net/manual/en/imagick.setimagepage.php
I have read once that the header of the gif might not say the correct image size in some cases. This is why it is useful to set the image page any way.
Example:
`$image->resizeImage(120, 110, imagick::FILTER_CATROM, 1);
// Set the page size
$image->setImagePage(120, 110, 0, 0);
i wanted to create a thumbnail with specific custom width & height. The function am using only create a thumbnail with a maximum set width/height.
How do i tweak the below function to give me a defined width/height e.g 50x50, 75x75, 100x100.
$original_photo = "photos/photo.extension";
$newcopy = "photos/thumbnails/photo.extension";
$copy_w = 50;
$copy_h = 50;
$extension = explode('.', 'photo.extension');
$extension = end($extension);
function create_thumbnail($original_photo, $newcopy, $copy_w, $copy_h, $extension) {
list($original_w, $original_h) = getimagesize($original_photo);
$scale_ratio = $original_w / $original_h;
if (($copy_w / $copy_h) > $scale_ratio) {
$copy_w = $copy_h * $scale_ratio;
} else {
$copy_h = $copy_w / $scale_ratio;
}
$img = '';
if ($extension == 'gif') {
$img = imagecreatefromgif($original_photo);
} elseif ($extension == 'png') {
$img = imagecreatefrompng($original_photo);
} else {
$img = imagecreatefromjpeg($original_photo);
}
$true_color = imagecreatetruecolor($copy_w, $copy_h);
imagecopyresampled($true_color, $img, 0, 0, 0, 0, $copy_w, $copy_h, $original_w, $original_h);
if (imagejpeg($true_color, $newcopy, 80) == true) {
return true;
} else {
return false;
}
}
Working with images in PHP/GD can be a pain. There are a lot of edge cases, particularly when transparent PNG/GIFs are manipulated.
If possible, I shamelessly recommend a library I wrote to handle things like this: SimpleImage 3.0
Using SimpleImage, you can achieve the desired effect with the following code:
// Load the image from image.jpg
$image = new \claviska\SimpleImage('image.jpg');
// Create a 50x50 thumbnail, convert to PNG, and write to thumbnail.png
$image->thumbnail(50, 50)->toFile('thumbnail.png', 'image/png');
See this page for more details on how the thumbnail method works and available arguments.
I have this code to upload multiple image. It is working fine.
<?php
include('db.php');
session_start();
$session_id='1'; //$session id
$path = "uploads/";
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name))
{
$ext = getExtension($name);
if(in_array($ext,$valid_formats))
{
if($size<(1024*1024))
{
$inputFileName = $_FILES['photoimg']['name'];
$actual_image_name = time().substr(str_replace(" ", "_", $ext), 5).".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
{
mysql_query("UPDATE users SET profile_image='$actual_image_name' WHERE uid='$session_id'");
echo "<img src='uploads/".$actual_image_name."' class='preview'>";
}
else
echo "Fail upload folder with read access.";
}
else
echo "Image file size max 1 MB";
}
else
echo "Invalid file format..";
}
else
echo "Please select image..!";
exit;
}
?>
But I want to create thumbnail for per image. To do this I have another one. I have found it from a website...but I can't understand how to integrate with my original one.
function thumbnail($inputFileName, $maxSize = 100)
{
$info = getimagesize($inputFileName);
$type = isset($info['type']) ? $info['type'] : $info[2];
// Check support of file type
if ( !(imagetypes() & $type) )
{
// Server does not support file type
return false;
}
$width = isset($info['width']) ? $info['width'] : $info[0];
$height = isset($info['height']) ? $info['height'] : $info[1];
// Calculate aspect ratio
$wRatio = $maxSize / $width;
$hRatio = $maxSize / $height;
// Using imagecreatefromstring will automatically detect the file type
$sourceImage = imagecreatefromstring(file_get_contents($inputFileName));
// Calculate a proportional width and height no larger than the max size.
if ( ($width <= $maxSize) && ($height <= $maxSize) )
{
// Input is smaller than thumbnail, do nothing
return $sourceImage;
}
elseif ( ($wRatio * $height) < $maxSize )
{
// Image is horizontal
$tHeight = ceil($wRatio * $height);
$tWidth = $maxSize;
}
else
{
// Image is vertical
$tWidth = ceil($hRatio * $width);
$tHeight = $maxSize;
}
$thumb = imagecreatetruecolor($tWidth, $tHeight);
if ( $sourceImage === false )
{
// Could not load image
return false;
}
// Copy resampled makes a smooth thumbnail
imagecopyresampled($thumb, $sourceImage, 0, 0, 0, 0, $tWidth, $tHeight, $width, $height);
imagedestroy($sourceImage);
return $thumb;
}
/**
* Save the image to a file. Type is determined from the extension.
* $quality is only used for jpegs.
* Author: mthorn.net
*/
function imageToFile($im, $fileName, $quality = 80)
{
if ( !$im || file_exists($fileName) )
{
return false;
}
$ext = strtolower(substr($fileName, strrpos($fileName, '.')));
switch ( $ext )
{
case '.gif':
imagegif($im, $fileName);
break;
case '.jpg':
case '.jpeg':
imagejpeg($im, $fileName, $quality);
break;
case '.png':
imagepng($im, $fileName);
break;
case '.bmp':
imagewbmp($im, $fileName);
break;
default:
return false;
}
return true;
}
$im = thumbnail('temp.jpg', 100);
imageToFile($im, 'temp-thumbnail.jpg');
Help will be greatly appreciated...
You can use following;
<?php
....
if(move_uploaded_file($tmp, $path.$actual_image_name)) {
// Create thumbnail here
$thumb = thumbnail($path.$actual_image_name, "80"); // image name, and size
imageToFile($thumb, 'path/to/thumb/thumbnail_' . $session_id . '.jpg');
mysql_query("UPDATE users SET profile_image='$actual_image_name' WHERE uid='$session_id'");
echo "<img src='uploads/".$actual_image_name."' class='preview'>";
}
...
?>
Do not forget to add thumbnail and imageToFile to put in your php file
<?php
// thumbnail configuration
$thumb_width = 50;
$thumb_height = 50;
$thumb_method = 'crop';
$thumb_bgColour = null; //array(255,240,240);
$thumb_quality = 70;
// Let script run for as long as it needs to when creating thumbnails.
// Some web hosts won't let you use this function. In that case you'll need
// to comment it out and just refresh the script until it has thumbnailed all the images.
set_time_limit(0);
// include the thumbnail function
require_once dirname(__FILE__) . '/paGdThumbnail.php';
// get the path to the current directory
$path = dirname(__FILE__);
// get the url for the images
$path_info = pathinfo($_SERVER['SCRIPT_NAME']);
$url = $path_info['dirname'];
// create an array to store image names in.
$images = array();
//$dir = new DirectoryIterator($path);
$file_name=$_REQUEST['big_img'];//$_FILES['big_img']['name'];
$file_path=$path.'\\'.$file_name;
/*
Loop through the directory, finding all images that aren't thumbnails.
For each image:
- if it doesn't already have a thumbnail, or the thumbnail is older than the image,
create a thumbnail.
- get info about the image
- add the image to our images array
*/
if( preg_match('#^(.+?)(_t)?\.(jpg|gif|png)#i', $file_name, $matches)){
list( ,$name, $is_a_thumb, $extension) = $matches;
// if its not a thumbnail
if( !$is_a_thumb ){
// does a valid thumbnail exist?
$has_thumb = false;
$thumb_file = $path . '/' . $matches[1] . '_t.jpg';
if( file_exists($thumb_file) && filemtime($thumb_file) > filemtime($file_path) ){
$has_thumb = true;
}
else{
// no thumbnail, so we shall create one!
// create a gd image. reading the contents of the image file into a string, then
// using imagecreatefromstring saves having to check the filetype and which
// imagecreatefrom(jpeg/gif/png) function to use
$image = imagecreatefromstring(file_get_contents($file_path));
if( $image ){
// create the thumbnail
$thumb = paGdThumbnail($image, $thumb_width, $thumb_height, $thumb_method, $thumb_bgColour);
// free the image resource
imagedestroy($image);
if( $thumb ){
// save the thumbnail
if( imagejpeg($thumb, $thumb_file, $thumb_quality) ){
$has_thumb = true;
}
// free the memory used by the thumbnail image
imagedestroy($thumb);
}
}
}
if( $has_thumb ){
$images[$file_name] = $name;
}
}
}
// sort the images array so always in the same order
ksort($images);
// end or processing, now display the gallery
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Thumbnails :</title>
<style type="text/css">
<!--
#thumbs{
position: relative;
}
#thumbs div{
float: left;
width: <?php echo $thumb_width + 30?>px;
height: <?php echo $thumb_height + 30?>px;
text-align: center;
}
#thumbs a:link img, #thumbs a:visited img{
border: 1px solid #acacac;
padding: 5px;
}
#thumbs a:hover img{
border: 1px solid black;
}
-->
</style>
</head>
<body>
<div id="thumbs">
<?php foreach( $images as $imagename => $name ){ ?>
<div>
<img src="<?php echo $url . '/' . $name . '_t.jpg'?>" />
</div>
<?php }?>
</div>
</body>
</html>
I'm looking for some help.
I have the following code which uploads the image & creates a thumbnail and stores them in the appropriate folders... But my problem is space.. the uploaded main images are HUGE 4320 x 3240 and the site takes ages to load...
I only want 2 images: A main image max width 1024, and a thumbnail max width 100....
UPDATE: Now works and resizes main image and creates thumbnail but only works on small image sizes < 2500px wide... but I need it to work on an image 4320px wide....
here's my code so far:
<?php ob_start();
session_start();
include("../../config.php");
ini_set("memory_limit", "500M");
$folder = "../images/stock/".$_SESSION['info_id']."";
$thumbs =$folder.'/thumbs/';
if(!file_exists($folder)){
mkdir ($folder,0777);
$uploadfolder = $folder."/";
//echo $folder.'<br>';
}
else
{
//echo 'folder already created<br>';
$uploadfolder = $folder."/";
//echo $folder.'<br>';
}
if(!file_exists($thumbs)){
mkdir($thumbs,0777);
$thumbnailfolder = $thumbs ;
//echo $thumbs.'<br>';
}else{
$thumbnailfolder = $thumbs ;
//echo $thumbnailfolder.'<br>';
}
$allowedfiletypes = array("jpeg","jpg");
//$uploadfolder = $s;
$thumbnailheight = 100; //in pixels
$imagesresizeheight = 500;
$action = $_POST['action'];
if ($action == "upload") {
//$_SESSION['result'] = "Uploading image... " ;
if(empty($_FILES['uploadimage']['name'])){
$_SESSION['result'] = "<strong>Error: File not uploaded 1!</strong><br>" ;
} else {
$uploadfilename = $_FILES['uploadimage']['name'];
$fileext = strtolower(substr($uploadfilename,strrpos($uploadfilename,".")+1));
if (!in_array($fileext,$allowedfiletypes)) { $_SESSION['result'] = "<strong>Error: Invalid file extension!</strong><br>" ; }
else {
$fulluploadfilename = $uploadfolder.$uploadfilename ;
if (move_uploaded_file($_FILES['uploadimage']['tmp_name'], $fulluploadfilename)) {
$im = imagecreatefromjpeg($fulluploadfilename);
if (!$im) { $_SESSION['result'] = "<p><strong>Error: Couldn't Resize Image!</strong><br>" ; }
else {
//// Resize Image Creation //////
$imw = imagesx($im); // uploaded image width
$imh = imagesy($im); // uploaded image height
$nh = $imagesresizeheight; // thumbnail height
$nw = round(($nh / $imh) * $imw); //thumnail width
$newim = imagecreatetruecolor ($nw, $nh);
imagecopyresampled ($newim,$im, 0, 0, 0, 0, $nw, $nh, $imw, $imh) ;
$imagefilename = $uploadfolder.$uploadfilename ;
imagejpeg($newim, $imagefilename) or die($_SESSION['result'] ="<strong>Error: Couldn't save image resize!</strong><br>");
echo $imw. $imh. $nw. $imagefilename;
//// Thumbnail Creation //////
$imw = imagesx($im); // uploaded image width
$imh = imagesy($im); // uploaded image height
$nh = $thumbnailheight; // thumbnail height
$nw = round(($nh / $imh) * $imw); //thumnail width
$newim = imagecreatetruecolor ($nw, $nh);
imagecopyresampled ($newim,$im, 0, 0, 0, 0, $nw, $nh, $imw, $imh) ;
$thumbfilename = $thumbnailfolder.$uploadfilename ;
imagejpeg($newim, $thumbfilename) or die($_SESSION['result'] ="<strong>Error: Couldn't save thumnbail!</strong><br>");
//echo $thumbfilename;
//$_SESSION['result'] ='<img src="'.$thumbfilename.'"/><br>' ;
}
} else { $_SESSION['result'] = "<strong>Error: Couldn't save file($fulluploadfilename)!</strong><br>";
}
}
}
}
//unlink($fulluploadfilename);
////////////////////////////////////////////////
//connect to mysql server
$c = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB);
if (!$c){
$_SESSION['result'] .= mysql_error().'<br>';
return;
}
if (!mysql_select_db(DB)){
$_SESSION['result'] .= mysql_error().'<br>';
mysql_close($c);
return;
}
//5. insert settings
$sql = "INSERT INTO photo(photo_id,photo_filename) VALUES ('".$_SESSION['info_id']."','".$uploadfilename."')";
if (!mysql_query($sql,$c)){
mysql_close($c);
return;
}
mysql_close($c);
//////////////////////////////////////////////
//$ref = getenv("HTTP_REFERER");
//header("Location: ".$ref);
?>
just
unlink($fulluploadfilename);
after all thumbnails are created.
I have a snippet of code used to upload images into my gallery. All seems to work until it gets to the last part of the code.
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$pubID = $_POST['pubID'];
$size = 260; // the thumbnail height
$filedir = '../images/gallery/'.$pubID.'/'; // the directory for the original image
$thumbdir = '../images/gallery/'.$pubID.'/thumb/'; // the directory for the thumbnail image
$maxfile = '2000000';
$mode = '0777';
$userfile_name = $_FILES['Gallimage']['name'];
$userfile_tmp = $_FILES['Gallimage']['tmp_name'];
$userfile_size = $_FILES['Gallimage']['size'];
$userfile_type = $_FILES['Gallimage']['type'];
if (isset($_FILES['Gallimage']['name']))
{
$prod_img = $filedir.$userfile_name;
$prod_img_thumb = $thumbdir.$userfile_name;
move_uploaded_file($userfile_tmp, $prod_img);
chmod ($prod_img, octdec($mode));
$sizes = getimagesize($prod_img);
$aspect_ratio = $sizes[1]/$sizes[0];
if ($sizes[1] <= $size)
{
$new_width = $sizes[0];
$new_height = $sizes[1];
}else{
$new_height = $size;
$new_width = abs($new_height/$aspect_ratio);
}
$destimg=ImageCreateTrueColor($new_width,$new_height)
or die('Problem In Creating image');
$srcimg=ImageCreateFromJPEG($prod_img)
or die('Problem In opening Source Image');
if(function_exists('imagecopyresampled'))
{
imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg))
or die('Problem In resizing');
}else{
Imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg))
or die('Problem In resizing');
}
ImageJPEG($destimg,$prod_img_thumb,90)
or die('Problem In saving');
imagedestroy($destimg);
}
The error arrives on this line: ImageJPEG($destimg,$prod_img_thumb,90).
Here is the error code line 84 being the : ImageJPEG($destimg,$prod_img_thumb,90)
Warning: imagejpeg() [function.imagejpeg]: Unable to open '../images/gallery/264/thumb/Hair-Salon-1.jpg' for writing: No such file or directory in /home/www/public_html/console/gallery.php on line 84. Problem In saving
It's conceivable that the directory '../images/gallery/'.$pubID.'/thumb/' does not exist. Try to use mkdir('../images/gallery/'.$pubID.'/thumb/', 0775, true) and see what happens. This should create writable directories along the path, down to thumb at the end.
Try this code with a bit more error checking, a few corrections and some general improvements. Everything commented, if you don't understand anything just ask:
// Try not to over-use parenthesis, it makes code less readable. You only need them to group conditions.
if (isset($_POST["MM_insert"]) && $_POST["MM_insert"] == "form1") {
// Pass through basename() for sanitization
$pubID = basename($_POST['pubID']);
$size = 260; // the thumbnail height
$filedir = '../images/gallery/'.$pubID.'/'; // the directory for the original image
$thumbdir = '../images/gallery/'.$pubID.'/thumb/'; // the directory for the thumbnail image
$maxfile = '2000000';
// PHP understands proper octal representations - no need to turn it into a string
$mode = 0777;
if (isset($_FILES['Gallimage']['name'])) {
// Get upload info and create full paths
$userfile_name = $_FILES['Gallimage']['name'];
$userfile_tmp = $_FILES['Gallimage']['tmp_name'];
$userfile_size = $_FILES['Gallimage']['size'];
$userfile_type = $_FILES['Gallimage']['type'];
$prod_img = $filedir.$userfile_name;
$prod_img_thumb = $thumbdir.$userfile_name;
// Create directories if they don't exist - this is the crux of your problem
if (!is_dir($filedir)) {
mkdir($filedir, $mode, TRUE)
or die('Unable to create storage directory');
}
if (!is_dir($thumbdir)) {
mkdir($thumbdir, $mode, TRUE))
or die('Unable to create thumb directory');
}
// Move it to the correct location and set permissions
move_uploaded_file($userfile_tmp, $prod_img)
or die('Unable to move file to main storage directory');
chmod($prod_img, $mode)
or die('Unable to set permissions of file');
// Get info about the image
$sizes = getimagesize($prod_img);
$aspect_ratio = $sizes[1] / $sizes[0];
if ($sizes[1] <= $size) {
$new_width = $sizes[0];
$new_height = $sizes[1];
} else {
$new_height = $size;
$new_width = abs($new_height / $aspect_ratio);
}
// Create image resources
$destimg = imagecreatetruecolor($new_width, $new_height)
or die('Problem in creating image');
$srcimg = imagecreatefromjpeg($prod_img)
or die('Problem in opening source Image');
// Manipulate the image
if (function_exists('imagecopyresampled')) {
imagecopyresampled($destimg, $srcimg, 0, 0, 0, 0, $new_width, $new_height, imagesx($srcimg), imagesy($srcimg))
or die('Problem in resizing');
} else {
imagecopyresized($destimg, $srcimg, 0, 0, 0, 0, $new_width, $new_height, imagesx($srcimg), imagesy($srcimg))
or die('Problem in resizing');
}
// Save the thumbnail and destroy the resources
imagejpeg($destimg, $prod_img_thumb, 90)
or die('Problem in saving');
imagedestroy($destimg);
}
// More code here? If not, merge all of this into a single if block
}