frank Mitglied
Angemeldet: 24.09.2005 Beiträge: 319
|
Verfasst am: 26.05.2006, 17:32 Titel:
Image resize Problem |
|
|
|
|
hab hier nen code um bilder zu verkleinern. (nur wenn größer als die angegebenen max.werte.
funktioniert bis auf den gif teil problemlos.
jemand ne idee, was bei dem nicht passt?
Code: | <?php
//avatar resize
$maxavawidth = 150;
$maxavaheight = 100;
$filename = addslashes(strip_tags($_GET['img']));
$upfile = "../images/avatar/" . $filename;
$fsize = filesize($upfile);
if ($fsize > 0) {
$ext = strtolower(substr(strrchr($filename, "."), 1));
$size = GetImageSize($upfile); // Read the size
$width = $size[0];
$height = $size[1];
// Proportionally resize the image to the
// max sizes specified above
$x_ratio = $maxavawidth / $width;
$y_ratio = $maxavaheight / $height;
if( ($width <= $maxavawidth) && ($height <= $maxavaheight) )
{
$tn_width = $width;
$tn_height = $height;
}
elseif (($x_ratio * $height) < $maxavaheight)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $maxavawidth;
}
else
{
$tn_width = ceil($y_ratio * $width);
$tn_height = $maxavaheight;
}
// Increase memory limit to support larger files
ini_set('memory_limit', '32M');
// Create the new image!
if($ext == "jpg" OR $ext == "jpeg") {
Header("Content-type: image/jpeg");
$src = ImageCreateFromJPEG($upfile);
$dst = ImageCreateTrueColor($tn_width, $tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
ImageJpeg($dst);
}
elseif($ext == "gif") {
header("Content-type: image/gif");
$src = ImageCreateFromGIF($upfile);
$dst = ImageCreateTrueColor($tn_width, $tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
ImageGif($dst);
}
elseif($ext == "png") {
header("Content-type: image/png");
$src = ImageCreateFromPNG($upfile);
$dst = ImageCreateTrueColor($tn_width, $tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
ImagePng($dst);
}
// Destroy the images
ImageDestroy($src);
ImageDestroy($dst);
}
?> |
|
|
Impi Mitglied
Angemeldet: 06.05.2006 Beiträge: 530
|
Verfasst am: 26.05.2006, 18:28 Titel:
|
|
|
|
|
Ähm, sehe ich das richtig du willst Avatare verkleinert anzeigen lassen?
Wieso so schwer ...
Schau mal:
Code: |
function easy_thumb($image, $maxsize) {
if($image && !preg_match("/[a-zA-Z]:\/\//si", $image)) {
$image = "http://$image";
} else {
$image = $image;
$fp = fopen($image, "rb");
$size = getimagesize($image);
if($size[0] AND $size[1] > $maxsize) {
if($size[0] AND $size[1] > 1000) {
$width = $size[0]/5;
$height = $size[1]/5;
$thumb = '<a href="'.$image.'" target="_Blank"><img src="'.$image.'" width="'.$width.'" height="'.$height.'" border="0"></a>';
} else {
$width = $size[0]/3;
$height = $size[1]/3;
$thumb = '<a href="'.$image.'" target="_Blank"><img src="'.$image.'" width="'.$width.'" height="'.$height.'" border="0"></a>';
};
} else {
$thumb = '<img src="'.$image.'" border="0">';
};
return $thumb;
};
};
|
So ist es auch weniger Servercpufressend
Impi |
|
syrec Mitglied
Angemeldet: 03.03.2006 Beiträge: 163
|
Verfasst am: 26.05.2006, 18:47 Titel:
|
|
|
|
|
Impi hat folgendes geschrieben: | Ähm, sehe ich das richtig du willst Avatare verkleinert anzeigen lassen?
Wieso so schwer ...
Schau mal:
Code: |
function easy_thumb($image, $maxsize) {
if($image && !preg_match("/[a-zA-Z]:\/\//si", $image)) {
$image = "http://$image";
} else {
$image = $image;
$fp = fopen($image, "rb");
$size = getimagesize($image);
if($size[0] AND $size[1] > $maxsize) {
if($size[0] AND $size[1] > 1000) {
$width = $size[0]/5;
$height = $size[1]/5;
$thumb = '<a href="'.$image.'" target="_Blank"><img src="'.$image.'" width="'.$width.'" height="'.$height.'" border="0"></a>';
} else {
$width = $size[0]/3;
$height = $size[1]/3;
$thumb = '<a href="'.$image.'" target="_Blank"><img src="'.$image.'" width="'.$width.'" height="'.$height.'" border="0"></a>';
};
} else {
$thumb = '<img src="'.$image.'" border="0">';
};
return $thumb;
};
};
|
So ist es auch weniger Servercpufressend
Impi |
so wie ich das sehe will er das bild verkleinern nicht kleiner anzeigen lassen.... |
|