2013-08-18 6 views
2

Je dois ajouter un filigrane sur l'image. J'ai résolu en utilisant ce code, fonctionne bien, mais l'image est positionnée sur le coin gauche/bas. Comment définir le filigrane central sur le centre de l'image?Filigrane du centre sur l'image

$img = 'test.jpg'; 
// Load the image where the logo will be embeded into 
$image = imagecreatefromjpeg($img); 


// Load the logo image 
$logoImage = imagecreatefrompng("watermark.png"); 
imagealphablending($logoImage, true); 

// Get dimensions 
$imageWidth=imagesx($image); 
$imageHeight=imagesy($image); 

$logoWidth=imagesx($logoImage); 
$logoHeight=imagesy($logoImage);  

// Paste the logo 
imagecopy(
    // destination 
    $image, 
    // source 
    $logoImage, 
    // destination x and y 
    $imageWidth-$logoWidth, $imageHeight-$logoHeight,  
    // source x and y 
    0, 0, 
    // width and height of the area of the source to copy 
    $logoWidth, $logoHeight); 

// Set type of image and send the output 
header("Content-type: image/png"); 
imagePng($image); 

// Release memory 
imageDestroy($image); 
imageDestroy($imageLogo); 

Répondre

4

remplacer

// destination x and y 
    $imageWidth-$logoWidth, $imageHeight-$logoHeight, 

avec

// destination x and y 
    ($imageWidth-$logoWidth)/2, ($imageHeight-$logoHeight)/2 

,

+0

Je vois. Je ne le savais pas. – Sylverdrag

0

http://gloryplus.com/index.php?route=product/product&path=81&product_id=285

 for($i=0; $i < $count; $i++) 
    { 
     ("'".$im[$i]."'"); 

     $imVar = imagecreatefromjpeg($im[$i]); 
     // First we create our stamp image manually from GD 
     $stamp = imagecreatefromgif('a.gif'); //imagecreatetruecolor(100, 54); 

     // Set the margins for the stamp and get the height/width of the stamp image 
     $marge_right = 10; 
     $marge_bottom = 10; 
     $sx = imagesx($stamp); 
     $sy = imagesy($stamp); 


     // Merge the stamp onto our photo with an opacity (transparency) of 50% 
     imagecopymerge($imVar, $stamp, imagesx($imVar) - $sx - $marge_right, imagesy($imVar) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50); 

     // Save the image to file and free memory 
     imagepng($imVar, "./image/image[$i].png"); 
    }