Image resizing

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
calvinklein

Sat Jun 19, 2010 11:00 am

Hi,

You can use image resizing php scripts like timthumb, imagemagick etc

Goodluck
php web development india

lokanath7
New php-forum User
New php-forum User
Posts: 139
Joined: Mon Nov 15, 2010 12:11 am

Wed Nov 24, 2010 12:53 am

/*---------try this and give the arguments correctly and let me know is it working in ur server correctly or not-----*/

function resizeImage($originalImage,$toWidth,$toHeight,$ext){

// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$xscale=$width/$toWidth;
$yscale=$height/$toHeight;

// Recalculate new size with default ratio
if($toWidth > $width && $toHeight > $height)
{
$new_width = $width;
$new_height = $height;
}
else
{
if ($yscale>$xscale){
$new_width = round($width * (1/$yscale));
$new_height = round($height * (1/$yscale));
}
else {
$new_width = round($width * (1/$xscale));
$new_height = round($height * (1/$xscale));
}
}
// Resize the original image
$imageResized = imagecreatetruecolor($toWidth, $toHeight);
$bg=imagecolorallocate ( $imageResized, 255, 255, 255 );
imagefill ( $imageResized, 0, 0, $bg );

switch($ext) {
case 'jpg':
$imageTmp = imagecreatefromjpeg($originalImage);
break;
case 'jpeg':
$imageTmp = imagecreatefromjpeg($originalImage);
break;
case 'png':
$imageTmp = imagecreatefrompng($originalImage);
break;
case 'gif':
$imageTmp = imagecreatefromgif($originalImage);
break;
default:
$err = 1;
//die;
break;
}
imagecopyresampled($imageResized, $imageTmp, ($toWidth-$new_width)/2, ($toHeight-$new_height)/2, 0, 0, $new_width, $new_height, $width, $height);

return $imageResized;
}

User avatar
webinfopedia
New php-forum User
New php-forum User
Posts: 84
Joined: Sat May 21, 2011 10:26 pm
Contact:

Fri Jun 10, 2011 4:05 am

Hi
Here is one of my article to create thumbnail image from a large with small file size. Read the below article and download example file..
http://www.webinfopedia.com/create-thum ... g-PHP.html

Hope this is what you looking for...
Thank you

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests