You last visited: Today at 12:53
Advertisement
Imagecopy/Imageresize Frage
Discussion on Imagecopy/Imageresize Frage within the Web Development forum part of the Coders Den category.
09/26/2012, 15:37
#1
elite*gold: 0
Join Date: Oct 2010
Posts: 1,587
Received Thanks: 151
Imagecopy/Imageresize Frage
Hallo,
bei meinem momentanen Website Projekt will ich unter das bild, eine art Watermark hinzufügen wie hier der fall:
Also das grau hinterlegte mit dem more on ragecomic.de meine ich.
genau das selbe will ich nun für meine Website realisieren, bekomme es aber nicht hin.
Ich habe momentan das ganze mit einem "Stempel" gelöst, aber das find ich auch nicht so wirklich eine schöne Lösung.
Deshalb dachte ich mir ich will es genauso machen wie dort, aber leider weiß ich nicht genau wie ich es realiesieren soll.
Ganz grundlegend, wäre es ja folgendermaßen zu realisieren:
PHP Code:
<?php
$imgsrc = imagecreatefrompng ( GRAFIKVERWEIS );
$watermark = imagecreatefrompng ( "watermark.png" );
$width = imagesx ( $imgsrc );
$height = imagesy ( $imgsrc );
$wWidth = imagesx ( $watermark );
$wHeight = imagesy ( $watermark );
$img = imagecreatetruecolor ( $width , $height );
imagecopy ( $img , $imgsrc , 0 , 0 , 0 , 0 , $width , $height );
imagecopy ( $img , $watermark , ( $width - $wWidth ), ( $height - $wHeight ), 0 , 0 , $wWidth , $wHeight );
imagepng ( $img , SPEICHERORT + DATEINAME );
imagedestroy ( $img );
?>
Mein Problem nun ist, das ich es nicht auf mein "script" angepasst bekomme bzw. es einfach nicht so hinbekomme wie bei dem Ragecomic Beispiel.
Mein jetztiges "Stempelskript" ist folgendes:
PHP Code:
if( $config [ 'wm' ] == "1" )
{
$watermark = $config [ 'imagedir' ]. "/" . $config [ 'watermark' ];
if( $thepp2 == ".png" )
{
$img = imagecreatefrompng ( $config [ 'pdir' ]. "/t/l-" . $thepp );
}
elseif( $thepp2 == ".jpg" )
{
$img = imagecreatefromjpeg ( $config [ 'pdir' ]. "/t/l-" . $thepp );
}
else
{
$wskip = "1" ;
}
if( $wskip != "1" )
{
$img_width = imagesx ( $img );
$img_height = imagesy ( $img );
$watermark = imagecreatefrompng ( $watermark );
$watermark_width = imagesx ( $watermark );
$watermark_height = imagesy ( $watermark );
$image = imagecreatetruecolor ( $watermark_width , $watermark_height );
imagealphablending ( $image , false );
$dest_x = $img_width - $watermark_width - 5 ;
$dest_y = $img_height - $watermark_height - 5 ;
imagecopy ( $img , $watermark , $dest_x , $dest_y , 0 , 0 , $watermark_width , $watermark_height );
imagesavealpha ( $img , true );
imagejpeg ( $img , $config [ 'pdir' ]. "/t/l-" . $thepp , 90 );
}
if( $thepp2 == ".png" )
{
$img = imagecreatefrompng ( $config [ 'pdir' ]. "/t/" . $thepp );
}
elseif( $thepp2 == ".jpg" )
{
$img = imagecreatefromjpeg ( $config [ 'pdir' ]. "/t/" . $thepp );
}
else
{
$wskip = "1" ;
}
if( $wskip != "1" )
{
$img_width = imagesx ( $img );
$img_height = imagesy ( $img );
$image = imagecreatetruecolor ( $watermark_width , $watermark_height );
imagealphablending ( $image , false );
$dest_x = $img_width - $watermark_width - 5 ;
$dest_y = $img_height - $watermark_height - 5 ;
imagecopy ( $img , $watermark , $dest_x , $dest_y , 0 , 0 , $watermark_width , $watermark_height );
imagesavealpha ( $img , true );
imagejpeg ( $img , $config [ 'pdir' ]. "/t/" . $thepp , 90 );
}
}
$query = "UPDATE posts SET pic=' $thepp ' WHERE PID='" . mysql_real_escape_string ( $pid ). "'" ;
$conn -> execute ( $query );
header ( "Location: $config [ baseurl ] /jest/" . $pid . "?new=1" );exit;
}
}
}
}
}
}
}
}
Ich würde mich wirklich über hilfe von euch freuen
MfG,
Gelsas
09/26/2012, 19:17
#2
elite*gold: 0
Join Date: Sep 2005
Posts: 427
Received Thanks: 87
Hier was zum lesen
PHP Code:
<?php #requirements: #php4+, gd 2.0.1+ class SignImage { var $offset_x = 0 ; var $offset_y = 0 ; var $quality = 100 ; var $image_type = - 1 ; // Image type: 1 = GIF, 2 = JPG, 3 = PNG var $force_image_type = - 1 ; // Change image type? (-1 = same as original, 1 = GIF, 2 = JPG, 3 = PNG) var $save_to_file = true ; function SignImage ( $image_path = '' , $offset_x = 0 , $offset_y = 0 ) { $this -> setImagePath ( $image_path ); $this -> setOffset ( $offset_x , $offset_y ); } function setImagePath ( $image_path ) { $this -> image_path = $image_path ; } function setOffset ( $x , $y ) { $this -> offset_x = $x ; $this -> offset_y = $y ; } function ImageCreateFromType ( $type , $filename ) { $im = null ; switch ( $type ) { case 1 : $im = ImageCreateFromGif ( $filename ); break; case 2 : $im = ImageCreateFromJpeg ( $filename ); break; case 3 : $im = ImageCreateFromPNG ( $filename ); break; } return $im ; } function ApplySign ( $sign_path ) { $this -> sign_path = $sign_path ; $size = getimagesize ( $this -> image_path ); $size_x = $size [ 0 ]; $size_y = $size [ 1 ]; $image_type = $size [ 2 ]; // 1 = GIF, 2 = JPG, 3 = PNG $image = $this -> ImageCreateFromType ( $image_type , $this -> image_path ); $wsize = getimagesize ( $sign_path ); $sign_x = $wsize [ 0 ]; $sign_y = $wsize [ 1 ]; $sign_type = $wsize [ 2 ]; // 1 = GIF, 2 = JPG, 3 = PNG $sign = $this -> ImageCreateFromType ( $sign_type , $sign_path ); $dest_x = $size_x - $sign_x - $this -> offset_x ; $dest_y = $size_y - $sign_y - $this -> offset_y ; imagecopymerge ( $image , $sign , $dest_x , $dest_y , 0 , 0 , $sign_x , $sign_y , 100 ); $this -> image = & $image ; $this -> sign = & $sign ; $this -> image_type = $image_type ; } function OutputImageInternal ( $filename = '' ) { $im = & $this -> image ; $res = null ; $image_type = ( $this -> force_image_type != - 1 ? $this -> force_image_type : $this -> image_type ); if(( $image_type == 1 ) && ! function_exists ( 'imagegif' )) $image_type = 3 ; switch ( $image_type ) { case 1 : if ( $this -> save_to_file ) $res = ImageGIF ( $im , $filename ); else { header ( "Content-type: image/gif" ); $res = ImageGIF ( $im ); } break; case 2 : if ( $this -> save_to_file ) $res = ImageJPEG ( $im , $filename , $this -> quality ); else { header ( "Content-type: image/jpeg" ); $res = ImageJPEG ( $im , NULL , $this -> quality ); } break; case 3 : if ( PHP_VERSION >= '5.1.2' ) { $quality = 9 - min ( round ( $this -> quality / 10 ), 9 ); if ( $this -> save_to_file ) { $res = ImagePNG ( $im , $filename , $quality ); } else { header ( "Content-type: image/png" ); $res = ImagePNG ( $im , NULL , $quality ); } } else { if ( $this -> save_to_file ) { $res = ImagePNG ( $im , $filename ); } else { header ( "Content-type: image/png" ); $res = ImagePNG ( $im ); } } break; } return $res ; } function Output ( $type = - 1 ) { $this -> force_image_type = $type ; $this -> save_to_file = false ; $this -> OutputImageInternal (); } function SaveAsFile ( $filename , $type = - 1 ) { $this -> force_image_type = $type ; $this -> save_to_file = true ; $this -> OutputImageInternal ( $filename ); } function Free () { imagedestroy ( $this -> image ); imagedestroy ( $this -> sign ); } } ?>
PHP Code:
<?php $img_dir = '/www/gfx/' ; // Verzeichnis von den Ausgangs Bildern $dest_dir = '/www/gfx/dest/' ; // Verzeichnis der finalen Bilder $img_sign = 'sign.png' ; //Das Stempelbild include( "class.sign.php" ); foreach ( glob ( $img_dir . "*.jpg" ) as $filename ) { $img_dest_dir = $dest_dir . basename ( $filename ); $img = new SignImage ( $img_dir ); $img -> ApplySign ( $img_sign ); $img -> SaveAsFile ( $img_dest_dir ); $img -> Free (); } ?>
10/11/2012, 18:13
#3
elite*gold: 0
Join Date: Oct 2010
Posts: 1,587
Received Thanks: 151
Danke, ich bekomme es aber leider nicht, hin gibt es hier jemanden der mir helfen könnte?
ich würde den/die person dann auch bezahlen.
mfg
10/12/2012, 07:38
#4
elite*gold: 2
Join Date: May 2011
Posts: 448
Received Thanks: 110
Ich hab mir auch gerade den Code oben durchgelesen. Schau nochmal genau drüber der hilft dir bei allen Problemen
Aber aufpassen imageresize ist ziemlich schlampig!
Similar Threads
Frage zu Bot machen-Maus Frage-Button Frage
02/16/2012 - AutoIt - 10 Replies
Hallo,
Elitepvpers hat echt für alles ein Ort :D Geil.
Also...Bin AutoIt anfänger.
Ich bin dabei ein Bot für das Online Game Runescape zu machen.
Ich hette 2 Fragen(FÜR DEN MOMMENT :) ):
Kann ich machen das AutoIt inaktiv die Maus benutzt,also werend der Bot läuft das ich bzw. man im Internet surft oder was anderes macht`?
All times are GMT +2. The time now is 12:53 .