hello ppl?
i want to create thumbnail image. in other words an image resizer.
is there any function in php for it.
i mean i want a function where i will give one of both height or width and i will resize the image for me !
Regards !
how create a thumbnail?
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
You need to use the GD library:
http://de2.php.net/manual/en/function.i ... esized.php
has the following example
This could be used as a starting point.
http://de2.php.net/manual/en/function.i ... esized.php
has the following example
Code: Select all
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreate($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
?>- itsmani1
- Forum Regular
- Posts: 791
- Joined: Mon Sep 29, 2003 2:26 am
- Location: Islamabad Pakistan
- Contact:
Code: Select all
$imgfile = '2.jpg';
Header("Content-type: image/".$_GETї"type"]);
switch($_GETї"type"]){
default:
$function_image_create = "ImageCreateFromJpeg";
$function_image_new = "ImageJpeg";
break;
case "jpg":
$function_image_create = "ImageCreateFromJpeg";
$function_image_new = "ImageJpeg";
case "jpeg":
$function_image_create = "ImageCreateFromJpeg";
$function_image_new = "ImageJpeg";
break;
case "png":
$function_image_create = "ImageCreateFromPng";
$function_image_new = "ImagePNG";
break;
case "gif":
$function_image_create = "ImageCreateFromGif";
$function_image_new = "ImagePNG";
break;
}
list($width, $height) = getimagesize($imgfile);
// the new weight of the thumb
$newheight = 80;
// Proportion is maintained
$newwidth = (int) (($width*80)/$height);
$thumb = ImageCreateTrueColor($newwidth,$newheight);
$source = @function_image_create($imgfile);
ImageCopyResized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
@$function_image_new($thumb);Fatal error: Call to undefined function: imagecreatetruecolor() in c:\apache\htdocs\images\resize.php on line 69
wot could be the problem !
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany