Hi.
ich habe folgendes skript, dass aus bildern Thumbnails macht:
<?php
// Funktion: Thumbnail erstellen
// =============================
function thumbnail($image_path, $image_name, $thumbnail_path, $thumbnail_name, $thumbnail_width)
{
// always create a thumbnail image,
// regardless of original image size
$always_thumbnail = true;
// image properties:
// [0]: width,
// [1]: height,
// [2]: type (*.jpg, *.gif, *.png...),
// [3]: file size
$image_size = getimagesize($image_path . $image_name);
// width of original image
$image_width = $image_size[0];
// height of original image
$image_height = $image_size[1];
// create thumbnail if original image is bigger than a thumbnail
if(
$image_width > $thumbnail_width ||
$always_thumbnail == true
)
{
// calculate thumbnail height
$thumbnail_height = intval($image_height / ($image_width / $thumbnail_width));
// create gif-thumbnail
if($image_size[2] == 1)
{
$old_gif = ImageCreateFromGIF($image_path . $image_name);
$new_gif = ImageCreate($thumbnail_width, $thumbnail_height);
ImageCopyResampled($new_gif, $old_gif, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $image_width, $image_height);
ImageGIF($new_gif, $thumbnail_path . $thumbnail_name);
}
// create jpg-thumbnail
if($image_size[2] == 2)
{
$old_jpg = ImageCreateFromJPEG($image_path . $image_name);
$new_jpg = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
ImageCopyResampled($new_jpg, $old_jpg, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $image_width, $image_height);
ImageJPEG($new_jpg, $thumbnail_path . $thumbnail_name);
}
// create png-thumbnail
if($image_size[2] == 3)
{
$old_png = ImageCreateFromPNG($image_path . $image_name);
$new_png = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
ImageCopyResampled($new_png, $old_png, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $image_width, $image_height);
ImagePNG($new_png, $thumbnail_path . $thumbnail_name);
}
}
}
?>
bei großen bildern (zb von der digicam) meckert der server dass er nicht genug ram hat:
Fatal error: Allowed memory size of 52428800 bytes exhausted (tried to allocate 15968 bytes) in /bla/bla/thumbnail_url.php on line 49
(25mb pro skript sind in meinem vertrag inbergriffen).
kann man das irgentwie optimieren?