Hackerboard Wiki HaboBlog
Hackerboard bei Facebook Hackerboard bei Google+ Hackerboard bei Twitter

[HaBo]

 
(Web-) Design und webbasierte Sprachen Tipps & Tricks, Designabgleich, HTML & Javascript, Flash, ASP, PHP, Perl/CGI...

Nach abarbeitung einer Klasse beendet sich script.

Diskussion: Nach abarbeitung einer Klasse beendet sich script. im Forum (Web-) Design und webbasierte Sprachen, in der Kategorie Web, Network & Multimedia Palace; Anzeige //ok gelöst nach langen probieren hab meine dateien jetzt auf maximal 8 mb beschränkt mehr lässt mein anbieter beim ...

Antwort
Alt 25.03.11, 18:48   #1 (permalink)
Senior Member
 
Benutzerbild von Chakky
 
Registriert seit: 28.10.03
Chakky Leistung: 8086
Chakky eine Nachricht über ICQ schicken
Likes: 110
erledigt Nach abarbeitung einer Klasse beendet sich script.

Anzeige

//ok gelöst nach langen probieren

hab meine dateien jetzt auf maximal 8 mb beschränkt mehr lässt mein anbieter beim hochladen eh nicht zu.Obwohl maximal 64MB Memorylimit für in der php.ini festgelegt sind.

hab mich noch einen kleinen trick bedient und zwar lass ich das Bild erst kleiner machen bevor ich das Watermark setze. Jetzt läuft er nicht mehr in ein Limit rein

//lösung ende

Hallo,

ich hab jetzt folgendes Problem:
Ich habe mir aus diesen Thread: Nützliche kleine PHP und JavaScript Funktionen

die Imageclass genommen:
inhalt der image.class.php

PHP-Code:
<?php
//error_reporting(E_ALL);
/**
 * image-object, where you can edit the image (resize / rotate)
 * works with gdlib!
 * @author Martin Bergann <martin@cs-bergann.de>
 *
 */
class Image {

    private 
$_path;
    private 
$_img null;
    private 
$_infos null;
    private 
$_error = array();
    private 
$_exif = array();
    private 
$_error_msg = array(
        
'0' => '',
        
'1' => 'error while loading image',
        
'2' => 'error while saving image',
        
'3' => 'invalid dimensions',
        
'4' => 'no image loaded'
    
);


    
/* Constructor / Destructor */

    
public function __construct($path='') {
        if (!empty(
$path))
            
$this->loadImage($path);
    }

    
/* load and save */

    
public function loadImage($path) {
        
$this->_path $path;
        if (!
$this->_infos = @getimagesize($path)) {
            
array_push($this->_error1);
            return 
false;
        }

        
//    var_dump($this->_infos);

        
if ($this->_infos[2] == 1) {
            
// Bild ist vom Typ gif
            
$this->_img = @imagecreatefromgif($this->_path);
        } elseif (
$this->_infos[2] == 2) {
            
// Bild ist vom Typ jpg
            
$this->_img = @imagecreatefromjpeg($this->_path);
            
$this->_exif exif_read_data($this->_pathfalsetrue);
        } elseif (
$this->_infos[2] == 3) {
            
// Bild ist vom Typ png
            
$this->_img = @imagecreatefrompng($this->_path);
        } else {
            
array_push($this->_error2);
            return 
false;
        }

        return 
true;
    }

    
/**
     * saves images by filename-extension
     */
    
public function saveImage($path$quality 90) {
        
$dir dirname($path);
        
$dirName basename($dir);
        
$parentDir dirname($dir);
        if (!
file_exists($dir)) {
            if (!
is_dir($parentDir) || !is_writable($parentDir)) {
                
array_push($this->_error2);
                return 
false;
            }
            
mkdir($dir);
        } elseif (!
is_dir($dir) || !is_writable($dir)) {
            
array_push($this->_error2);
            return 
false;
        }

        switch (
strtolower($this->getFilenameExtension($path))) {
            case 
'jpg':
            case 
'jpeg':
                if (!@
imagejpeg($this->_img$path$quality)) {
                    
array_push($this->_error2);
                    return 
false;
                }
                break;
            case 
'gif':
                if (!@
imagegif($this->_img$path)) {
                    
array_push($this->_error2);
                    return 
false;
                }
                break;
            case 
'png':
                if (!@
imagepng($this->_img$path$quality)) {
                    
array_push($this->_error2);
                    return 
false;
                }
                break;
            default:
                break;
        }
        
$this->loadImage($path);
        return 
true;
    }

    public function 
getExif() {
        return 
$this->_exif;
    }

    public function 
generateImage($width$height$color) {
        
$this->_img imagecreatetruecolor($width$height);
        
imagefill($this->_img00$color);
    }

    public function 
createTextImage($text$fontfile$fontsize$text_color=0xFFFFFF$background_color=0$fontangle=0) {
        if (!
is_numeric($fontsize)) {
            
$fontsize 20;
        }
        if (!
is_numeric($fontangle)) {
            
$fontangle 0;
        }

        
//get size of text-field
        
$textfield imagettfbbox($fontsize$fontangle$fontfile$text);
        
$text_size_x = (abs($textfield[4] - $textfield[0]) + 10);
        
$text_size_y = (abs($textfield[1] - $textfield[7]) + 10);
        
$text_pos_x 3;
        
$text_pos_y $fontsize 5;

        
$text_picture imagecreatetruecolor($text_size_x$text_size_y);

        
$t_red = ($text_color >> 16) & 0xFF;
        
$t_green = ($text_color >> 8) & 0xFF;
        
$t_blue = ($text_color) & 0xFF;

        
$b_red = ($background_color >> 16) & 0xFF;
        
$b_green = ($background_color >> 8) & 0xFF;
        
$b_blue = ($background_color) & 0xFF;

        
$background_color imagecolorallocate($text_picture$b_red$b_green$b_blue);
        
$text_color imagecolorallocate($text_picture$t_red$t_green$t_blue);

        
imagefill($text_picture00$background_color);
        
imagettftext($text_picture$fontsize$fontangle$text_pos_x$text_pos_y$text_color$fontfile$text);
        
//if(isset($this->_img))imagedestroy($this->_img);
        
$this->_img $text_picture;
    }

    public function 
getImageRessource() {
        return 
$this->_img;
    }

    
/* get infos */


 
    
public function getOrigWidth() {
        return 
$this->_infos[0];
    }

    public function 
getOrigHeight() {
        return 
$this->_infos[1];
    }

    public function 
getCurrentWidth() {
        return (!
is_null($this->_img)) ? imagesx($this->_img) : 0;
    }

    public function 
getCurrentHeight() {
        return (!
is_null($this->_img)) ? imagesy($this->_img) : 0;
    }

    public function 
getOrigMime() {
        return 
$this->_infos['mime'];
    }

    public function 
getOrigFilenameExtension() {
        return 
$this->getFilenameExtension($this->_path);
    }

    protected function 
getFilenameExtension($path) {
        return 
preg_replace('/^.*\.([0-9a-z]+)$/i''\\1'$path);
    }

    
/* Errors */

    
public function hasError() {
        return (
sizeof($this->_error) != 0);
    }

    public function 
getErrorMsg() {
        
$r '';
        foreach (
$this->_error as $errno) {
            
$r.='Error ' $errno ' : ' $this->_error_msg[$errno] . chr(10);
        }
        return 
$r;
    }

    
/* manipulate image */

    
public function rotate($degree$bg=0) {
        try {
            
$img imagerotate($this->_img$degree$bg);
        } catch (
Exception $e) {
            echo 
$e;
        }

        
imagedestroy($this->_img);
        
$this->_img $img;
    }

    
/**
     * mode:
     * 0 = use long side to scale and override short side
     * 1 = use short side to scale and override long side
     * 2 = use width to scale and override height
     * 3 = use height to scale and override width
     * --
     * 4 = use width and height - add a black (or any other color) background to fill
     * 5 = use width and height - zoom to the center and cut the rest of the image
     */
    
public function resizeProportional($width$height$mode=0$bgcol=0) {
        
$new_w 0;
        
$new_h 0;

        if (
$mode == 5) {
            
$img imagecreatetruecolor($width$height);
            
imagefill($img00$bgcol);
            
$ratio $this->getCurrentHeight() / $this->getCurrentWidth();
            
$new_ratio $height $width;
            if (
$ratio $new_ratio) {
                
//cut left and right
                
$new_h $height;
                
$new_w $height $ratio;
                
$diff = ($width $new_w);
                
imagecopyresampled($img$this->_img$diff 2000$width $diff$height$this->getCurrentWidth(), $this->getCurrentHeight());
            } else {
                
//cut top and bottom
                
$new_w $width;
                
$new_h $width $ratio;
                
$diff = ($height $new_h);
                
imagecopyresampled($img$this->_img0$diff 200$width$height $diff$this->getCurrentWidth(), $this->getCurrentHeight());
            }
            
imagedestroy($this->_img); /* nötig? */
            
$this->_img $img;
        } elseif (
$mode == 4) {
            
$img imagecreatetruecolor($width$height);
            
imagefill($img00$bgcol);
            
$ratio $this->getCurrentHeight() / $this->getCurrentWidth();
            
$new_ratio $height $width;
            if (
$new_ratio $ratio) {
                
//border at top and bottom
                
$new_w $width;
                
$new_h $width $ratio;
                
$diff = ($height $new_h);
                
imagecopyresampled($img$this->_img0$diff 200$width$height $diff$this->getCurrentWidth(), $this->getCurrentHeight());
            } else {
                
//border left and right
                
$new_h $height;
                
$new_w $height $ratio;
                
$diff = ($width $new_w);
                
imagecopyresampled($img$this->_img$diff 2000$width $diff$height$this->getCurrentWidth(), $this->getCurrentHeight());
            }
            
imagedestroy($this->_img); /* nötig? */
            
$this->_img $img;
        } elseif (
$mode == || ($mode == && $this->getCurrentHeight() >= $this->getCurrentWidth()) || ($mode == && $this->getCurrentHeight() <= $this->getCurrentWidth())) {
            
$ratio $this->getCurrentWidth() / $this->getCurrentHeight();
            
$new_h $height;
            
$new_w $ratio $height;
            
$this->resize($new_w$new_h);
        } else {
            
$ratio $this->getCurrentHeight() / $this->getCurrentWidth();
            
$new_w $width;
            
$new_h $ratio $width;
            
$this->resize($new_w$new_h);
        }
    }

    public function 
resize($width$height) {
        if (!
is_numeric($width) || $width <= || !is_numeric($height) || $height <= 0) {
            
array_push($this->_error3);
            return 
false;
        }
        
$img imagecreatetruecolor($width$height);
        
imagecopyresampled($img$this->_img0000$width$height$this->getCurrentWidth(), $this->getCurrentHeight());
        
imagedestroy($this->_img); /* nötig? */
        
$this->_img $img;
    }

    public function 
crop($top$left$bottom$right) {
        
$nw = ($right $left);
        
$nh = ($bottom $top);
        
$img imagecreatetruecolor($nw$nh);
        
imagecopyresampled($img$this->_img00$left$top$nw$nh$nw$nh);
        
imagedestroy($this->_img);
        
$this->_img $img;
    }

    public function 
setTransparentColor($transparentColor$toleranz=10) {
        if (
is_null($this->_img)) {
            
array_push($this->_error4);
            return 
false;
        }
        
//split index to red green and blue:
        
$t_red = ($transparentColor >> 16) & 0xFF;
        
$t_green = ($transparentColor >> 8) & 0xFF;
        
$t_blue = ($transparentColor) & 0xFF;
        
/* info:
         *     combining the three colors to the color-index:
         *     $transparentColor=($t_red<<16)|($t_green<<8)|($t_blue);
         */

        //fill all pixel within a defined tolerance with the transparentColor
        
for ($ix 0$ix $this->getCurrentWidth(); $ix++) {
            for (
$iy 0$iy $this->getCurrentHeight(); $iy++) {
                
$farbindex imagecolorat($this->_img$ix$iy);
                
$p_red = ($farbindex >> 16) & 0xFF;
                
$p_green = ($farbindex >> 8) & 0xFF;
                
$p_blue = ($farbindex) & 0xFF;
                if ((
$p_red >= ($t_red $toleranz) && $p_red <= $t_red $toleranz) && ($p_green >= ($t_green $toleranz) && $p_green <= $t_green $toleranz) && ($p_blue >= ($t_blue $toleranz) && $p_blue <= $t_blue $toleranz)) {
                    
imagesetpixel($this->_img$ix$iy$transparentColor);
                }
            }
        }

        
imagecolortransparent($this->_img$transparentColor);
    }

    public function 
addWatermarkImageObject($ImageObject$opacity=50$posX=null$posY=null) {
        if (
is_null($posX))
            
$posX $this->getCurrentWidth() / - ($ImageObject->getCurrentWidth() / 2);
        if (
is_null($posY))
            
$posY $this->getCurrentHeight() / - ($ImageObject->getCurrentHeight() / 2);
        if (
is_null($this->_img)) {
            
array_push($this->_error4);
            return 
false;
        }
        
imagecopymerge($this->_img$ImageObject->getImageRessource(), $posX$posY00$ImageObject->getCurrentWidth(), $ImageObject->getCurrentHeight(), $opacity);
    }

    public function 
addWatermarkImageRessource($Image$opacity=50$posX=null$posY=null) {
        if (
is_null($posX))
            
$posX $this->getCurrentWidth() / - (imagesx($Image) / 2);
        if (
is_null($posY))
            
$posY $this->getCurrentHeight() / - (imagesx($Image) / 2);
        if (
is_null($this->_img)) {
            
array_push($this->_error4);
            return 
false;
        }
        
imagecopymerge($this->_img$Image$posX$posY00imagesx($Image), imagesx($Image), $opacity);
    }

    public function 
addWatermark($watermarkFile$opacity=50$posX=null$posY=null$angle=0$transparentColor=null$resizeW=null$resizeH=null$resizeMode=null) {

        
$watermark = new Image($watermarkFile);

        if (
is_null($resizeMode)) {
            if (!
is_null($resizeW) && !is_null($resizeH))
                
$watermark->resize($resizeW$resizeH);
        }
        else {
            if (!
is_null($resizeW) && !is_null($resizeH))
                
$watermark->resizeProportional($resizeW$resizeH$resizeMode);
        }
        
//im Fehler-Fall beenden
        
if ($watermark->hasError())
            return 
false;

        
$watermark->rotate($angle$transparentColor);
        
$watermark->setTransparentColor($transparentColor);
        
$this->addWatermarkImageObject($watermark$opacity$posX$posY);
    }

    public function 
showJPG() {
        if (
is_null($this->_img)) {
            
array_push($this->_error4);
            return 
false;
        }
        
header('Content-type: image/jpeg');
        
imagejpeg($this->_img);
    }

    public function 
showPNG() {
        if (
is_null($this->_img)) {
            
array_push($this->_error4);
            return 
false;
        }
        
header('Content-type: image/png');
        
imagepng($this->_img);
    }

}
Die habe ich jetzt mal Testweise in meinen php Script eingebaut:
Mein Code:
PHP-Code:
<?php
error_reporting
(E_ALL);
include(
'image.class.php');

$orig "1140.jpg";




$img = new Image($orig);

$img->addWatermark(
        
'watermark.jpg'//watermark-image
        
100//opacity
        
NULL//pos x
        
NULL//pos y
        
0// angle
        
0xFFFFFF // transparent color
);
echo 
"vor save";
$img->saveImage($orig);

echo 
"nach save";
?>

<img src="1140.jpg">
Das Script soll nur auf das Bild ein Watermark setzen. Folgendes Problem tritt jetzt auf:
alles was nach
Code:
$img->saveImage($orig);
wird nicht mehr ausgeführt. PHP bringt mir keinerlei fehlermeldungen und in den Logfiles ist auch nix zu sehen.

Ich konnte aber feststellen das "saveImage" noch ausgeführt wird. Bei manchen Dateien (von der größe unterschiedlich und kein System festzustellen) wird das Script weiterhin ausgeführt bei anderen nicht, aber jedesmal wird trotzdem noch ein Watermark gesetzt.

Kann mir jemand erklären warum und vorallem wie ich das beheben kann?

ich hab es mit
PHP-Code:
 try { } und catch() {} 
versucht aber damit kann man die dinge nicht abfangen.

Danke

//update:

nach dem überall mal das @ entfernt habe in der klasse gibts auch ne fehlermedlung:

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 2460 bytes)

Ok es läuft in ein Speicherlimit ich versuch dann mal das limit per php.ini hochzusetzen, wenn das nicht klappt sonst jemand eine Idee?
__________________
cu
Chakky

we are dreaming in digital
we are living in realtime
we are thinking in binary
we are talking in IP
welcome to our world

Geändert von Chakky (25.03.11 um 20:07 Uhr) Grund: Gelöst!
Chakky ist offline   Mit Zitat antworten
Antwort
   
- Anzeige -

Werbung ist gerade online    

[HaBo] » Web, Network & Multimedia Palace » (Web-) Design und webbasierte Sprachen » PHP Nach abarbeitung einer Klasse beendet sich script.
Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind aus
Pingbacks sind aus
Refbacks sind aus



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61