Hi there!
Try this:
PHP Code:
function createThumb($source)
{
$thumb_size = 150;
$size = getimagesize($source);
$width = $size[0];
$height = $size[1];
if($width > $height)
{
$x = ceil( ( $width - $height ) / 2 );
$width = $height;
}
elseif($height > $width)
{
$y = ceil( ( $height - $width ) / 2 );
$height = $width;
}
$new_im = ImageCreatetruecolor($thumb_size,$thumb_size);
$im = imagecreatefromjpeg($source);
imagecopyresampled($new_im, $im, 0, 0, $x, $y, $thumb_size, $thumb_size, $width, $height);
imagejpeg($new_im, '', 100);
}
Make sure it's a JPEG-image you send, else you also must use imagegif() and imagepng etc.
Hopes this was usefull info!
----------------------------------
Edit:
----------------------------------
I forgoted, you can never call the createThumb()-function in a img-tag directly. You must add the the function in a own file let's say thumbnail.php,
Thumbnail.php:
PHP Code:
<?php
function createThumb($source)
{
$thumb_size = 150;
$size = getimagesize($source);
$width = $size[0];
$height = $size[1];
if($width > $height)
{
$x = ceil( ( $width - $height ) / 2 );
$width = $height;
}
elseif($height > $width)
{
$y = ceil( ( $height - $width ) / 2 );
$height = $width;
}
$new_im = ImageCreatetruecolor($thumb_size,$thumb_size);
$im = imagecreatefromjpeg($source);
imagecopyresampled($new_im, $im, 0, 0, $x, $y, $thumb_size, $thumb_size, $width, $height);
imagejpeg($new_im, '', 100);
}
$path = "upload/$pic1";
createThumb($path);
?>
Then you have the page where youre image-tag call the thumbnail.ph, let's say it's name is getImage.php,
getImage.php
PHP Code:
<html>
<head>
<title>Get image</title>
</head>
<body>
<img src="thumbnail.php">
</body>
</html>
I hopes you understand how I mean!
Best regards,
mbrodin
Bookmarks