PHP Forum

PHP Forum (http://www.selfphp.de/forum/index.php)
-   PHP für Fortgeschrittene und Experten (http://www.selfphp.de/forum/forumdisplay.php?f=13)
-   -   Thumbnail-Funktion liefert leere Seite (http://www.selfphp.de/forum/showthread.php?t=21984)

rarios 18.08.2009 13:25:53

Thumbnail-Funktion liefert leere Seite
 
Hallo!

Momentan bastele ich ein wenig an einem Foto-Upload-Script mit Thumbnailklasse.
Aus softwaretechnischen Gründen kann ich momentan aber keine Variablen der hochgeladenen Fotos erhalten.
Aus diesem Grund wird ein temporäres Verzeichnis ausgelesen.
Nun sollen Thumbnails erstellt werden.

Bei wenigen Dateien funktioniert dies auch wunderbar. ( Wenig = je nach Größe 2-6 )
Ist die Anzahl höher erhalte ich als Ausgabe eine leere Seite.

Wie umgehe ich dieses Problem sinnvoll, ohne das Script grundlegend zu verändern?

Liebe Grüße
rarios

PHP-Code:

<?php
error_reporting
(E_ALL);
session_start();
require_once(
"variables.inc.php");
require_once(
"functions.inc.php");
if (isset(
$_SESSION['albumsesid']))
{
$albumID $_SESSION['albumsesid'];
$dir scandir'../../images/pics/' ); 
foreach (
$dir as $picture)
    {
if ((
$picture == ".") OR ($picture == ".."))
        { } else {
$picnewreal "../../".GAL_ORIGINAL_PATH.$picture;
$picnewbig "../../".GAL_BIG_PATH."big_".$picture;
$picnewthumbnail "../../".GAL_THUMBNAIL_PATH."thumb_".$picture;
require_once(
"thumbnail.class.lib");
        
$thumbnail = new thumbnail();
        
$thumbnail->create($picnewreal);
        
$thumbnail->setQuality(90);
        
$thumbnail->resize("600");
        
$thumbnail->save($picnewbig);
        
$thumbnail->autocut(100,60,5);        
        
$thumbnail->save($picnewthumbnail);
        
unlink($picnewreal);
        
cms_mysql();
        
cms_mysql_insert("gallery","`albumID`, `title`, `original`, `thumbnail`","'".$albumID."','','big_".$picture."','thumb_".$picture."'");
        echo 
"Foto wurde erfolgreich hochgeladen und zur Galerie hinzugefügt!<br />";
unset(
$_SESSION["albumsesid"]);    
    }              }
} else { die(
"Zugriff nur über Interface möglich!"); }
?>

thumbnail.class.lib
PHP-Code:

<?php
class thumbnail
{
        var 
$img;
        var 
$fileInfo;
        var 
$fullName;
        var 
$newX;
        var 
$newY;
        var 
$quality;
        var 
$orgX;
        var 
$orgY;
        function 
create($data)
        {

                
$this->destroy();

                if (
file_exists($data)) {
                        
$this->img = @ImageCreateFromJpeg($data);
                        
$this->fileInfo basename($data);
                        
$this->fullName $data;
                } else {
                        
$this->img = @ImageCreateFromString($data);
                }

                if (!
$this->img) {
                        
$this->destroy();
                        return 
false;
                } else {
                        
$this->orgX ImageSX($this->img);
                        
$this->orgY ImageSY($this->img);
                        return 
true;
                }
        }
        function 
height()
        {
                if (
$this->img) {
                        return 
ImageSY($this->img);
                } else {
                        return 
false;
                }
        }
        function 
width()
        {
                if (
$this->img) {
                        return 
ImageSX($this->img);
                } else {
                        return 
false;
                }
        }

        function 
setQuality($quality false)
        {
                if (
$this->img && $quality) {
                        
$this->quality $quality;
                } else {
                        return 
false;
                }
        }
        function 
resize($newX false,$newY false)
        {
                if (
$this->img) {

                        
$X ImageSX($this->img);
                        
$Y ImageSY($this->img);

                        
$newX $this->_convert($newX,$X);
                        
$newY $this->_convert($newY,$Y);

                        if (!
$newX && !$newY) {
                                
$newX $X;
                                
$newY $Y;
                        }

                        if (!
$newX) {
                                
$newX round($X / ($Y $newY));
                        }

                        if (!
$newY) {
                                
$newY round($Y / ( $X $newX));
                        }

                        if ( ! 
$newimg ImageCreateTruecolor($newX,$newY)) {
                                
$newimg ImageCreate($newX,$newY);
                        }

                        if ( ! 
ImageCopyResampled ($newimg$this->img0000$newX$newY,$X,$Y)) {
                                
ImageCopyResized ($newimg$this->img0000$newX$newY,$X,$Y);
                        }

                        
$this->img $newimg;

                        return 
true;
                } else {
                        return 
false;
                }
        }
        function 
autocut($newX,$newY,$pos 5)
        {
                if (
$this->img) {

                        
$X ImageSX($this->img);
                        
$Y ImageSY($this->img);

                        
$newX $this->_convert($newX,$X);
                        
$newY $this->_convert($newY,$Y);

                        if (!
$newX) {
                                
$newX $X;
                        }

                        if (!
$newY) {
                                
$newY $Y;
                        }

                        switch (
$pos) {
                            case 
1:
                                
$srcX 0;
                                
$srcY 0;
                        break;

                            case 
2:
                                
$srcX round(($X 2)-($newX/2));
                                
$srcY 0;
                        break;

                            case 
3:
                                
$srcX ImageSX($this->img) - $newX;
                                
$srcY 0;
                        break;

                            case 
4:
                                
$srcX 0;
                                
$srcY round(($Y 2)-($newY/2));
                        break;

                            case 
5:
                                
$srcX round(($X 2)-($newX/2));
                                
$srcY round(($Y 2)-($newY/2));
                        break;

                            case 
6:
                                
$srcX $X-$newX;
                                
$srcY round(($Y 2)-($newY/2));
                        break;

                            case 
7:
                                
$srcX 0;
                                
$srcY $Y $newY;
                        break;

                            case 
8:
                                
$srcX round(($X 2)-($newX/2));
                                
$srcY $Y-$newY;
                        break;

                            case 
9:
                                
$srcX $X$newX;
                                
$srcY $Y $newY;
                        break;

                            default:
                                
$srcX round(($X 2)-($newX/2));
                                
$srcY round(($Y 2)-($newY/2));
                        }

                        return 
$this->cut($newX,$newY,$srcX,$srcY);
                } else {
                        return 
false;
                }
        }
        function 
maxSize($size)
        {
                if (
$this->img) {

                        
$X ImageSX($this->img);
                        
$Y ImageSY($this->img);

                        if (
$X $Y)
                        {
                                
$newX $size;
                                
$newY false;
                        } elseif (
$X $Y) {
                                
$newX false;
                                
$newY $size;
                        } else {
                                
$newX $size;
                                
$newY $size;
                        }
                        return 
$this->resize($newX,$newY);
                } else {
                        return 
false;
                }
        }
        function 
minSize($size)
        {
                if (
$this->img) {

                        
$X ImageSX($this->img);
                        
$Y ImageSY($this->img);


                        if (
$X $Y)
                        {
                                
$newX false;
                                
$newY $size;
                        } elseif (
$X $Y) {
                                
$newX $size;
                                
$newY false;
                        } else {
                                
$newX $size;
                                
$newY $size;
                        }
                        return 
$this->resize($newX,$newY);
                } else {
                        return 
false;
                }
        }
        function 
save($fileName$override true)
        {
                if (
$this->img) {
                        if (!
file_exists($fileName) || $override)  {
                                if (
ImageJPEG($this->img,$fileName,$this->quality)) {
                                        return 
true;
                                } else {
                                        return 
false;
                                }
                        } else {
                                return 
0;
                        }
                } else {
                        return 
false;
                }
        }
        function 
output($sendHeader true,$destroy true)
        {
                if (
$this->img) {

                                if (
$sendHeader) {
                                        
header("Content-type: image/jpeg");
                                }

                                
ImageJPEG($this->img,"",$this->quality);

                                if (
$destroy) {
                                        
$this->destroy();
                                }

                } else {
                        return 
false;
                }
        }
}
?>


DokuLeseHemmung 18.08.2009 15:46:43

AW: Thumbnail-Funktion liefert leere Seite
 
Wo ist $this->destroy(); definiert?
Und warum zerstörst du das Image nicht nach dem Save?
Klar sammeln sich dann die belegten Resourcen an.

Und wieso klebst du noch an PHP4?


Alle Zeitangaben in WEZ +2. Es ist jetzt 07:34:56 Uhr.

Powered by vBulletin® Version 3.8.3 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.