Wie in Bilder-Gallerie Wasserzeichen einfügen?

Grengou

Grünschnabel
Hey Leute,

brauche mal wider eure hilfe.
und das bei einem Bilder-Gallerie Script, die Gallerie macht nur ein Text Wasserzeichen rein aber ich möchte gerne das Bild Wasserzeichen rein machen.
Das ist der Script wo das Wasserzeichen reinkommt:
Code:
<?

import_request_variables( "gpc" );

require_once ( "inc_config.php" );
require_once ( "classes/p_picture.class.php" );
require_once ( "classes/p_mysql_db.class.php" );
require_once ( "classes/p_mediafile.class.php" );
require_once ( "classes/p_session.class.php" );

$o_db   = new p_MySQL_DB();
$o_pic  = new p_Picture();
$wasserzeichen = "kristallwasserzeichen.png";

$o_db->connect( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, "java_upload", "" );
$o_db->defineGalerieProperties( $galerie_id );

foreach( $_FILES as $tagname=>$objekt ){

     $upload_bild = $objekt["tmp_name"];
     $real_name   = $objekt["name"];

     $o_upload = new p_Mediafile( $real_name );
     if( $o_upload->isSupportedfile() ){
         $fn      = $o_upload->getUniqueFilename();
         $fn_pfad = DIR_PICS."/".$fn;
         if( move_uploaded_file( $upload_bild, $fn_pfad ) ){
             @chmod( $fn_pfad, 0775 );
             // wenn die EXIF-Bildinformationen ausgelesen werden müssen
             if( ENABLE_PIC_INFO ){
                $exif_info = $o_pic->readExifInfo( $fn_pfad );
                $exif_dat  = $o_pic->getExifDate();
             }
             // nur wenn das Bild signiert werden soll, muss es bearbeitet werden
             if( trim( PIC_SIGNATURE ) != "" && $o_upload->isResizeable() ){
                @chmod( $fn_pfad, 0777 );
                 
                $o_pic->getResizePicture( $fn_pfad, $fn_pfad, PIC_WIDTH, PIC_HEIGHT, "", true, DEFAULT_JPG_QUALITY, $wasserzeichen );
                @chmod( $fn_pfad, 0775 );
             }
             if( $o_db->addPicture( $album_id, $fn, $bemerkung, $exif_info, $exif_dat, $user ) ){
                echo "Ok";
             }
             else{
                echo "Fehler! ( beim DB-Eintrag ".$o_db->getErrorMessage()." )";
                @unlink( $fn_pfad );
             }
         }//if
         else{
            echo "Fehler! ( beim Verschieben )";
            @unlink( $fn_pfad );
         }
     }
     flush();
}

$o_db->disconnect();


?><?

import_request_variables( "gpc" );

require_once ( "inc_config.php" );
require_once ( "classes/p_picture.class.php" );
require_once ( "classes/p_mysql_db.class.php" );
require_once ( "classes/p_mediafile.class.php" );
require_once ( "classes/p_session.class.php" );

$o_db   = new p_MySQL_DB();
$o_pic  = new p_Picture();
$wasserzeichen = "wasserzeichen_text";

$o_db->connect( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, "java_upload", "" );
$o_db->defineGalerieProperties( $galerie_id );

foreach( $_FILES as $tagname=>$objekt ){

     $upload_bild = $objekt["tmp_name"];
     $real_name   = $objekt["name"];

     $o_upload = new p_Mediafile( $real_name );
     if( $o_upload->isSupportedfile() ){
         $fn      = $o_upload->getUniqueFilename();
         $fn_pfad = DIR_PICS."/".$fn;
         if( move_uploaded_file( $upload_bild, $fn_pfad ) ){
             @chmod( $fn_pfad, 0775 );
             // wenn die EXIF-Bildinformationen ausgelesen werden müssen
             if( ENABLE_PIC_INFO ){
                $exif_info = $o_pic->readExifInfo( $fn_pfad );
                $exif_dat  = $o_pic->getExifDate();
             }
             // nur wenn das Bild signiert werden soll, muss es bearbeitet werden
             if( trim( PIC_SIGNATURE ) != "" && $o_upload->isResizeable() ){
                @chmod( $fn_pfad, 0777 );
                 
                $o_pic->getResizePicture( $fn_pfad, $fn_pfad, PIC_WIDTH, PIC_HEIGHT, "", true, DEFAULT_JPG_QUALITY, $wasserzeichen );
                @chmod( $fn_pfad, 0775 );
             }
             if( $o_db->addPicture( $album_id, $fn, $bemerkung, $exif_info, $exif_dat, $user ) ){
                echo "Ok";
             }
             else{
                echo "Fehler! ( beim DB-Eintrag ".$o_db->getErrorMessage()." )";
                @unlink( $fn_pfad );
             }
         }//if
         else{
            echo "Fehler! ( beim Verschieben )";
            @unlink( $fn_pfad );
         }
     }
     flush();
}

$o_db->disconnect();


?>

wie kann ich das denn ändern?
 
In deinem Script sieht man gar nix, weil die Klasse die was macht hasst du nicht gepostet

PHP:
require_once ( "classes/p_picture.class.php" );
...
$o_pic  = new p_Picture();
...
$o_pic->getResizePicture( $fn_pfad, $fn_pfad, PIC_WIDTH, PIC_HEIGHT, "", true, DEFAULT_JPG_QUALITY, $wasserzeichen );

Die änderung müsste sein, dass du mit imagecopymerge() ein Bild kopierst
 
Hey yaslaw,

schon mal danke für den hinweis.

hier die pic...class.php
Code:
<?

class p_Picture{

    var $default_pic = "";
    var $exif_date   = "";
    var $arr_exif = array( "filename"                => 0,
                           "filedatetime"            => 0,
                           "filesize"                => 0,
                           "filetype"                => 0,
                           "mimetype"                => 0,
                           "imagedescription"        => 0,
                          //---- EXIF-Daten --------------
                           "make"                    => 0,
                           "model"                   => 0,
                           "xresolution"             => 0,
                           "yresolution"             => 0,
                           "software"                => 0,
                           "datetime"                => 0,
                           "exposuretime"            => 0,
                           "fnumber"                 => 0,
                           "isospeedratings"         => 0,
                           "exifversion"             => 0,
                           "datetimeoriginal"        => 0,
                           "datetimedigitized"       => 0,
                          //"componentsconfiguration" => 0,
                          //"filesource"              => 0,
                           "compressedbitsperpixel"  => 0,
                           "shutterspeedvalue"       => 0,
                           "aperturevalue"           => 0,
                           "exposurebiasvalue"       => 0,
                           "maxaperturevalue"        => 0,
                           "focallength"             => 0,
                           "flashpixversion"         => 0,
                           "exifimagewidth"          => 0,
                           "exifimagelength"         => 0,
                           "interoperabilityoffset"  => 0,
                           "digitalzoomratio"        => 0,
                           "focallengthin35mmfilm"   => 0,
                           "orientation"      => array( 1   => "ex_orientation_1",
                                                        2   => "ex_orientation_2",
                                                        3   => "ex_orientation_3",
                                                        4   => "ex_orientation_4",
                                                        5   => "ex_orientation_5",
                                                        6   => "ex_orientation_6",
                                                        7   => "ex_orientation_7",
                                                        8   => "ex_orientation_8" ),
                           "resolutionunit"   => array( 1   => "ex_resolutionunit_1",
                                                        2   => "ex_resolutionunit_2",
                                                        3   => "ex_resolutionunit_3" ),
                           "ycbcrpositioning" => array( 1   => "ex_ycbcrpositioning_1",
                                                        2   => "ex_ycbcrpositioning_2" ),
                           "exposureprogram"  => array( 0   => "ex_exposureprogram_0",
                                                        1   => "ex_exposureprogram_1",
                                                        2   => "ex_exposureprogram_2",
                                                        3   => "ex_exposureprogram_3",
                                                        4   => "ex_exposureprogram_4",
                                                        5   => "ex_exposureprogram_5",
                                                        6   => "ex_exposureprogram_6",
                                                        7   => "ex_exposureprogram_7",
                                                        8   => "ex_exposureprogram_8" ),
                           "meteringmode"     => array( 0   => "ex_meteringmode_0",
                                                        1   => "ex_meteringmode_1",
                                                        2   => "ex_meteringmode_2",
                                                        3   => "ex_meteringmode_3",
                                                        4   => "ex_meteringmode_4",
                                                        5   => "ex_meteringmode_5",
                                                        6   => "ex_meteringmode_6",
                                                        255 => "ex_meteringmode_255" ),
                           "lightsource"      => array( 0   => "ex_lightsource_0",
                                                        1   => "ex_lightsource_1",
                                                        2   => "ex_lightsource_2",
                                                        3   => "ex_lightsource_3",
                                                        4   => "ex_lightsource_4",
                                                        9   => "ex_lightsource_9",
                                                        10  => "ex_lightsource_10",
                                                        11  => "ex_lightsource_11",
                                                        12  => "ex_lightsource_12",
                                                        13  => "ex_lightsource_13",
                                                        14  => "ex_lightsource_14",
                                                        15  => "ex_lightsource_15",
                                                        17  => "ex_lightsource_17",
                                                        18  => "ex_lightsource_18",
                                                        19  => "ex_lightsource_19",
                                                        20  => "ex_lightsource_20",
                                                        21  => "ex_lightsource_21",
                                                        22  => "ex_lightsource_22",
                                                        23  => "ex_lightsource_23",
                                                        24  => "ex_lightsource_24",
                                                        255 => "ex_lightsource_255" ),
                           "flash"            => array( 0   => "ex_flash_0",
                                                        1   => "ex_flash_1",
                                                        5   => "ex_flash_5",
                                                        7   => "ex_flash_7",
                                                        9   => "ex_flash_9",
                                                        13  => "ex_flash_13",
                                                        15  => "ex_flash_15",
                                                        16  => "ex_flash_16",
                                                        24  => "ex_flash_24",
                                                        25  => "ex_flash_25",
                                                        29  => "ex_flash_29",
                                                        31  => "ex_flash_31",
                                                        32  => "ex_flash_32",
                                                        65  => "ex_flash_65",
                                                        69  => "ex_flash_69",
                                                        71  => "ex_flash_71",
                                                        73  => "ex_flash_73",
                                                        77  => "ex_flash_77",
                                                        79  => "ex_flash_79",
                                                        89  => "ex_flash_89",
                                                        93  => "ex_flash_93",
                                                        95  => "ex_flash_95" ),
                           "colorspace"        => array( 1   => "ex_colorspace_1",
                                                         0xFFFF => "ex_colorspace_ffff" ),
                           "sensingmethod"     => array( 1   => "ex_sensingmethod_1",
                                                         2   => "ex_sensingmethod_2",
                                                         3   => "ex_sensingmethod_3",
                                                         4   => "ex_sensingmethod_4",
                                                         5   => "ex_sensingmethod_5",
                                                         7   => "ex_sensingmethod_7",
                                                         8   => "ex_sensingmethod_8" ),
                           "scenetype"         => array( 1   => "ex_scenetype_1" ),
                           "exposuremode"      => array( 0   => "ex_exposuremode_0",
                                                         1   => "ex_exposuremode_1",
                                                         2   => "ex_exposuremode_2" ),
                           "whitebalance"      => array( 0   => "ex_whitebalance_0",
                                                         1   => "ex_whitebalance_1" ),
                           "scenecapturetype"  => array( 0   => "ex_scenecapturetype_0",
                                                         1   => "ex_scenecapturetype_1",
                                                         2   => "ex_scenecapturetype_2",
                                                         3   => "ex_scenecapturetype_3" ),
                           "sharpness"         => array( 0   => "ex_sharpness_0",
                                                         1   => "ex_sharpness_1",
                                                         2   => "ex_sharpness_2" )
                          );

    function p_Picture( $fn_default="" ){
        $this->default_pic = $fn_default;
    }


    //resize Picture ( thumbs, picture, fotos etc. )
    function getResizePicture( $fn_src, $fn_des, $width=-1, $height=-1, $fn_default="", $only_minimize=true, $qualitiy=82, $text="" ){

        //set default picture
        if( $fn_default == "" ) $fn_default = $this->default_pic;

        //if the picture no available
        if( is_file( $fn_src ) ){
            //if no set a size
            if( $width == -1 && $height == -1 ){
                $fn_pic = $fn_default;
            }
            else{
                $text   = trim( $text );
                $fn_pic = $fn_des;
                $info   = @getimagesize( $fn_src );
                $pw     = $info[0];
                $ph     = $info[1];
                $do_resize = (   ( $only_minimize && ( $ph > $height || $pw  > $width ) )
                              || ( $only_minimize == false ) );

                if( $do_resize || $text != "" ){

                    $pratio = $pw / $ph;
                    $ratio  = $width / $height;
                    if ( $ratio < $pratio) $height = ceil( $width /  $pratio );
                    else                   $width  = ceil( $height * $pratio );

                    switch($info[2]){
                    case 1: $im_src = imagecreatefromgif( $fn_src );
                            break;
                    case 2: $im_src = imagecreatefromjpeg( $fn_src );
                            break;
                    case 3: $im_src = imagecreatefrompng( $fn_src );
                            break;
                    }
                    if( $do_resize ){
                        $im_pic = imagecreatetruecolor( $width, $height );
                        imagecopyresampled( $im_pic, $im_src, 0 , 0 , 0 , 0, $width, $height, $pw, $ph );
                        if( $text != "" ){
                            $white = imagecolorallocate( $im_pic, 255, 255, 255 );
                            imagestring( $im_pic, 2, 10, $height-20, $text, $white );
                        }
                        imagejpeg( $im_pic, $fn_pic, $qualitiy );
                        imagedestroy( $im_src );
                        imagedestroy( $im_pic );
                    }
                    else{
                        $white = imagecolorallocate( $im_src, 255, 255, 255 );
                        imagestring( $im_src, 2, 10, $height-20, $text, $white );
                        imagejpeg( $im_src, $fn_pic, $qualitiy );
                        imagedestroy( $im_src );
                    }
                }
                else{
                    $fn_pic = $fn_src;
                }
            }
        }
        else{
            $fn_pic = $fn_default;
        }
        return $fn_pic;
    }

    // extrahiert ein Bild von einem Video mit MPlayer
    function getMPlayerPicture( $fn_video, $fn_pic, $dir_cmd, $width=-1, $fn_default="", $qualitiy=82 ){

        //set default picture
        if( $fn_default == "" ) $fn_default = $this->default_pic;
        $create_thumb = false;
        //if the picture no available
        if( is_file( $fn_video ) ){
             $tmp_dir = $dir_cmd."/tmp_".uniqid( rand(), false );
             if( mkdir( $tmp_dir ) ){
                $cmd = "$dir_cmd".DIRECTORY_SEPARATOR."mplayer -frames 1 -zoom -xy $width -nosound -vo jpeg:outdir=$tmp_dir:quality=$qualitiy $fn_video > nul 2> nul";
                // for error-debug -> fileoutput
                //$cmd = "$dir_cmd".DIRECTORY_SEPARATOR."mplayer -frames 1 -zoom -xy $width -nosound -vo jpeg:outdir=$tmp_dir:quality=$qualitiy $fn_video > mplayer_ok.log 2> mplayer_error.log";
                exec( $cmd );
                if( is_file( $tmp_dir."/00000001.jpg" ) && rename( $tmp_dir."/00000001.jpg", $fn_pic ) ){
                    $create_thumb = true;
                }
                rmdir( $tmp_dir );
             }
        }
        if( !$create_thumb ) $fn_pic = $fn_default;
        return $fn_pic;
    }

    function getFFMpegPicture( $fn_video, $fn_pic, $dir_cmd, $width=60, $height=60, $fn_default="" ){
        //ffmpeg -vframes 1 -i D:\Programme\ffmpeg\robot.avi -ss 00:00:01.000 -s 40x60 -y -f mjpeg D:\Programme\ffmpeg\frame.jpg
        //set default picture
        if( $fn_default == "" ) $fn_default = $this->default_pic;
        $create_thumb = false;
        //if the picture no available
        if( is_file( $fn_video ) ){
             $tmp_dir = $dir_cmd."/tmp";
             $tmp_fn  = $tmp_dir."/tmp_".uniqid( rand(), false );
             if( !is_dir( $tmp_dir ) ) mkdir( $tmp_dir );
             $cmd = "$dir_cmd".DIRECTORY_SEPARATOR."ffmpeg -vframes 1 -i $fn_video -ss 00:00:01.000 -s ".$width."x".$height." -y -f mjpeg $tmp_fn> nul 2> nul";
             // for error-debug -> fileoutput
             //$cmd = "$dir_cmd".DIRECTORY_SEPARATOR."ffmpeg -vframes 1 -i $fn_video -ss 00:00:01.000 -s ".$width."x".$height." -y -f mjpeg $tmp_fn> ffmpeg_ok.log 2> ffmpeg_error.log";
             @exec( $cmd );
             if( is_file( $tmp_fn ) && rename( $tmp_fn, $fn_pic ) ){
                  $create_thumb = true;
             }
        }
        if( !$create_thumb ) $fn_pic = $fn_default;
        return $fn_pic;
    }


    function readExifInfo( $fn ){
        $this->exif_date = "";
        if( stristr( $fn, ".jpg" ) ){
            //nur wenn die PHP-Funktion vorhanden ist
            if( function_exists( "exif_read_data" ) ){
                $exif = @exif_read_data( $fn, o, true );
                if( is_array( $exif ) ){
                    $arr_exif_keys = array_keys( $this->arr_exif );
                    foreach ($exif as $key => $section){
                        if( $key == "IFD0" || $key == "EXIF" || $key == "FILE" ){
                            foreach( $section as $name => $val ){
                                $name = strtolower( $name );
                                if( in_array( $name, $arr_exif_keys ) ){
                                    $rs .= "$name=$val\n";
                                    if( $name == "datetimeoriginal" ){
                                        //Format von 2006:07:01 17:42:05 nach 0000-00-00 00:00:00
                                        list( $datum, $uhrzeit ) = explode( " ", $val );
                                        $arr = explode( ":", $datum );
                                        $this->exif_date = $arr[0]."-".$arr[1]."-".$arr[2]." ".$uhrzeit;
                                    }
                                }
                            }
                        }
                    }
                }
                else $rs = "No EXIF-Information";
            }
            else $rs = "No EXIF-Service on PHP available";
        }
        return $rs;
    }

    function getExifDate(){
        return $this->exif_date;
    }


};

?>


kann einer was damit anfangen ?

ich nicht wirklich.
 
Ich programmier jetzt mal etwas dazwieschen. Kann es aber grad schlecht testen.

Die Anpassung soll bewirken, dass du anstelle des Textest wahlweise auch eine Imageressource übergeben kannst.

Zeile 155:
PHP:
                if (!is_ressource($text)) $text   = trim( $text );

Die folgenden Zeile 178-194
PHP:
                    if( $do_resize ){
                        $im_pic = imagecreatetruecolor( $width, $height );
                        imagecopyresampled( $im_pic, $im_src, 0 , 0 , 0 , 0, $width, $height, $pw, $ph );
                        if( $text != "" ){
                            $white = imagecolorallocate( $im_pic, 255, 255, 255 );
                            imagestring( $im_pic, 2, 10, $height-20, $text, $white );
                        }
                        imagejpeg( $im_pic, $fn_pic, $qualitiy );
                        imagedestroy( $im_src );
                        imagedestroy( $im_pic );
                    }
                    else{
                        $white = imagecolorallocate( $im_src, 255, 255, 255 );
                        imagestring( $im_src, 2, 10, $height-20, $text, $white );
                        imagejpeg( $im_src, $fn_pic, $qualitiy );
                        imagedestroy( $im_src );
                    }
ersetze ich mal durch
PHP:
                    if( $do_resize ){
                        $im_pic = imagecreatetruecolor( $width, $height );
                        imagecopyresampled( $im_pic, $im_src, 0 , 0 , 0 , 0, $width, $height, $pw, $ph );
                        if(is_ressource($text)){
                        	$wText = imagesx($text);
                        	$hText = imagesy($text);
                        	imagecopymerge($im_pic, $text, 10, $height-20, 0, 0, $wText, $hText, 20);
                        }elseif( $text != "" ){
                            $white = imagecolorallocate( $im_pic, 255, 255, 255 );
                            imagestring( $im_pic, 2, 10, $height-20, $text, $white );
                        }
                        imagejpeg( $im_pic, $fn_pic, $qualitiy );
                        imagedestroy( $im_src );
                        imagedestroy( $im_pic );
                    }
                    else{
                        if(is_ressource($text)){
                        	$wText = imagesx($text);
                        	$hText = imagesy($text);
                        	imagecopymerge($im_pic, $text, 10, $height-20, 0, 0, $wText, $hText, 20);
                       	} else {
	                        $white = imagecolorallocate( $im_src, 255, 255, 255 );
	                        imagestring( $im_src, 2, 10, $height-20, $text, $white );
	                        imagejpeg( $im_src, $fn_pic, $qualitiy );
	                        imagedestroy( $im_src );
						}
                    }

Und so sieht dann der Aufruf aus:
PHP:
$wasserzeichenimage = imagecreatefrimjpeg('mygrafik.jpg');
//ggf hiernoch eine Farbe als Transparent deklarieren -> imagecolortransparent()
$o_pic->getResizePicture( $fn_pfad, $fn_pfad, PIC_WIDTH, PIC_HEIGHT, "", true, DEFAULT_JPG_QUALITY, $wasserzeichenimage );
 
also habe alles so geändert aber erhalte jetzt beim upload die meldung und die bilder werden nicht hochgeladen
<b>Fatal error</b>: Call to undefined function: imagecreatefrimjpeg() in <b>/home/java_upload.php</b> on line <b>14</b><br />

das ist :
Code:
$wasserzeichenimage = imagecreatefrimjpeg('mygrafik.jpg');
//ggf hiernoch eine Farbe als Transparent deklarieren -> imagecolortransparent()
$o_pic->getResizePicture( $fn_pfad, $fn_pfad, PIC_WIDTH, PIC_HEIGHT, "", true, DEFAULT_JPG_QUALITY, $wasserzeichenimage );


# yaslaw

muss gerade weg, komme später noch mal on und werde es dann weiter versuchen.

Aber schon mal viellen dank für deine schnelle, gute und ausführliche hilfe.
 
item: Schreibfehler meinerseits: imagecreatefromjpeg, nicht ..f.rimjpeg
item: Natürlich musst du eine Grafik mit einem gültigen Pfad angeben.

Das ganze von mir dient nur als Idee. Schau dir in der PHP-Doku die Befehle nach die du nicht kennst.
Du weisst aber so wo das Wasserzeichen erstellt wird.
 
Hallo,

Ja ich habe es erst mal selber versucht es zu beheben aber hatte nicht get,.
is_ressource() soll is_resource() oder?

Mein grüßtes Problem ist das ich morgen wider übers Wer weg bin und daher frage ich so schelle um es vielleicht bis heute Abend hinzu kriegen.

Ach ja ich wollte eine .png Bild Datei nutzen dafür muss ich noch nur
imagecreatefromjpeg in imagecreatefrompng ändern oder?
 
Zurück