ERLEDIGT
NEIN
NEIN
ANTWORTEN
3
3
ZUGRIFFE
282
282
EMPFEHLEN
-
17.05.04 17:05 #1
Also
Ich hab mir gerade ein zufallsbilscript gebastelt das einen tumbnail generieren sollte. Macht es aber nicht
fehlermeldungPHP-Code:<?php
function thumb($file, $save, $width, $height, $prop = TRUE) {
// Requires GD-Lib > 2.0
// Ist $prop=TRUE, so werden die Proportionen des Bildes
// auch im Thumbnail eingehalten
@unlink($save);
$infos = @getimagesize($file);
if($prop)
{
// Proportionen erhalten
$iWidth = $infos[0];
$iHeight = $infos[1];
$iRatioW = $width / $iWidth;
$iRatioH = $height / $iHeight;
if ($iRatioW < $iRatioH)
{
$iNewW = $iWidth * $iRatioW;
$iNewH = $iHeight * $iRatioW;
}
else
{
$iNewW = $iWidth * $iRatioH;
$iNewH = $iHeight * $iRatioH;
} // end if
}
else
{
// Strecken und Stauchen auf Größe
$iNewW = $width;
$iNewH = $height;
}
if($infos[2] == 2)
{
// Bild ist vom Typ jpg
$imgA = imagecreatefromjpeg($file);
$imgB = imagecreatetruecolor($iNewW,$iNewH);
imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW,
$iNewH, $infos[0], $infos[1]);
imagejpeg($imgB, $save);
}
elseif($infos[2] == 3)
{
// Bild ist vom Typ png
$imgA = imagecreatefrompng($file);
$imgB = imagecreatetruecolor($iNewW, $iNewH);
imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW,
$iNewH, $infos[0], $infos[1]);
imagepng($imgB, $save);
}
else
{
return FALSE;
}
}
$to1 = '".$vn."/".$auswahl[$number]."';
$to2 = '".$vn."/".$auswahl[$number]."';
// Funktionsaufruf mit Einbehaltung der Proportionen
thumb($vn, $to1, 100, 75, TRUE);
// Funktionsaufruf ohne Einbehaltung der Proportionen
thumb($vn, $to2, 100, 75, FALSE);
$vn = "./screens";
$verzeichnis = opendir($vn);
while($file = readdir($verzeichnis)) {
$s = @getimagesize($vn."/".$file);
if(in_array($s[2], array(1,2,3)))
$auswahl[] = $file;
}
mt_srand((double)microtime()*1000000);
$number = mt_rand(0,count($auswahl)-1);
echo "<img src='".$vn."/".$auswahl[$number]."'>";
?>
www.gamedevelopmentcenter.de/nwn/pic.php
das Zufallsbild funktioniert ja, aber der tumbnail funktioniert ned wie man unschwer erkennt.
kann mir wer beim fixen helfen
-
18.05.04 08:24 #2
Was haben denn $iWidth und $iHeight für Werte? Denn die Fehlermeldung sagt ja was über ne Division durch Null, was bekanntlich nicht geht. Meine Vermutung daher, dass hier
etwas nicht stimmt. Wenn Du das "@" mal weglässt, dann kommen vielleicht auch noch ein paar Fehlermeldungen mehr, die Dir auf jeden Fall helfen könnten! Lass Dir auch mal $file ausgeben (echo($file)), dann siehst Du, ob der Pfad überhaupt stimmt.PHP-Code:$infos = @getimagesize($file);
-- j.
-
18.05.04 09:01 #3
Das hab ich auch schon versucht.
iheight und iwidth sollen eigentlich bei to1 und to2 dividiert werden
ich bin gestern den ganzen tag bei der fehlersuche gesessen hab aber nix gefunden.
gibts vielleicht irgendwo ein script das so funktioniert wie das gemurkse von mir funktionieren sollte
-
18.05.04 09:16 #4PHP-Code:
function ResizeImage($strImage, $iImageMaxX, $iImageMaxY, $imgPath, $imgName) {
//read Image
$sizeOfImage = getimagesize($strImage);
//scale
$width = $sizeOfImage[0];
$height = $sizeOfImage[1];
$max_width = $iImageMaxX;
$max_height = $iImageMaxY;
$x_ratio = $max_width/$width;
$y_ratio = $max_height/$height;
//if image smaller than $iImageMaxX x $iImageMaxY nothing happens
if($width <= $max_width && $height <= $max_height) {
$iNewWidth = $width;
$iNewHeight = $height;
}
//if image taller then scale
else if(($x_ratio * $height) < $max_height) {
$iNewHeight = ceil($x_ratio * $height);
$iNewWidth = $max_width;
}
//if image wider then scale
else {
$iNewWidth = ceil($y_ratio * $width);
$iNewHeight = $max_height;
}
//gif or jpg or png
switch ($sizeOfImage[2]) {
case 1:
$oldImage = ImageCreateFromGIF($strImage);
$imageType = "image/gif";
break;
case 2:
$oldImage = ImageCreateFromJPEG($strImage);
$imageType = "image/jpeg";
break;
case 3:
$oldImage = ImageCreateFromPNG($strImage);
$imageType = "image/png";
break;
}
//create new image
$newImage = ImageCreate($iNewWidth, $iNewHeight);
//resize
ImageCopyResized($newImage, $oldImage, 0, 0, 0, 0, $iNewWidth, $iNewHeight, ImageSX($oldImage), ImageSY($oldImage));
//create image
switch ($sizeOfImage[2])
{
case 1:
ImageGIF($newImage, "$imgPath$imgName");
break;
case 2:
ImageJPEG($newImage, "$imgPath$imgName", 70);
break;
case 3:
ImagePNG($newImage, "$imgPath$imgName");
break;
}
}
-- j.
Ähnliche Themen
-
Direkt nach Bildupload tumbnail erzeugen!!
Von CikoNo1 im Forum PHPAntworten: 9Letzter Beitrag: 23.08.05, 17:03 -
ZufallsBild - Problem: Nicht die selbe Ausgabe hintereinander !
Von motty im Forum PHPAntworten: 7Letzter Beitrag: 21.04.05, 14:12 -
Problem mit Zufallsbild auf eine Ebene zuweisen
Von RealSuain im Forum Javascript & AjaxAntworten: 1Letzter Beitrag: 10.02.05, 23:49 -
[PHP] function Problem
Von nDeedy im Forum PHPAntworten: 2Letzter Beitrag: 02.09.03, 18:19 -
Problem mit function
Von Dr_Ogen im Forum Flash PlattformAntworten: 2Letzter Beitrag: 28.08.03, 17:43





Zitieren
Login






[PHP][Snippet] Array zu XML konvertieren