Eine Funktion zum Erstellen von Thumbnails
<?php
/*
Thumbnails erstellen
Aktion: PHP Scripte für die armen dieser Welt
Der Erlös geht für mein Pausenbrot drauf
Copyright (c) 2004 by Phillip 'Firebird' Berndt
*/
if(!function_exists('file_get_contents'))
{
function file_get_contents($filename)
{
return implode('', file($filename));
}
}
function thumbnail($imgFile, $maxWidth = 200, $maxHeight = 150, $output = '')
{
if(!function_exists('imagecreatefromstring'))
trigger_error('GD Library not found', E_USER_ERROR);
if(!file_exists($imgFile))
trigger_error('File not found: '.$imgFile, E_USER_ERROR);
$image = imagecreatefromstring(file_get_contents($imgFile))
or trigger_error($imgFile.' is no valid image', E_USER_ERROR);
$oldSize = $imgSize = array(imagesx($image), imagesy($image));
if($imgSize[0] > $maxWidth)
{
$imgSize[1] *= $maxWidth / $imgSize[0];
$imgSize[0] = $maxWidth;
}
if($imgSize[1] > $maxHeight)
{
$imgSize[0] *= $maxHeight / $imgSize[1];
$imgSize[1] = $maxHeight;
}
if(function_exists('imagecreatetruecolor'))
{
$thumbnail = imagecreatetruecolor($imgSize[0], $imgSize[1]);
imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $imgSize[0], $imgSize[1], $oldSize[0], $oldSize[1]);
}
else
{
$thumbnail = imagecreate($imgSize[0], $imgSize[1]);
imagecopyresized($thumbnail, $image, 0, 0, 0, 0, $imgSize[0], $imgSize[1], $oldSize[0], $oldSize[1]);
}
imagedestroy($image);
if($output == '')
header('Content-type: image/jpeg');
imagejpeg($thumbnail, $output, 80);
imagedestroy($thumbnail);
}
thumbnail('Beispiel.jpg', 100, 100);
?>