2009-10-20 6 views
1

Je souhaite filigraner une image et l'enregistrer. voici le code que j'utilise pour cela. Ici, il sort l'image et stocke cette sortie dans le fichier. Je veux le sauvegarder sans le sortir.Filigrane d'image en php

// Load the stamp and the photo to apply the watermark to 
$stamp = imagecreatefrompng('stamp.png'); 
$im = imagecreatefromjpeg('proverbs.jpeg'); 

// 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); 

// Copy the stamp image onto our photo using the margin offsets and the photo 
// width to calculate positioning of the stamp. 
    imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp)); 

// Output and free memory 
header('Content-type: image/png'); 
ob_start(); 
// output jpeg (or any other chosen) format & quality 
imagejpeg($im, NULL, 85); 
// capture output to string 
$contents = ob_get_contents(); 
// end capture 
ob_end_clean(); 
//imagepng($im); 
imagedestroy($im); 
$fh = fopen("proverbs.jpeg", "w"); 
fwrite($fh, $contents); 
fclose($fh); 

Répondre

2

L'enregistrer dans un fichier?

changer simplement

imagejpeg($im, NULL, 85); 

à

imagejpeg($im, 'image.jpg', 85); 
+0

probelm est que son émission en sortie « http: // localhost/im age/index.php "sur l'écran. Je ne veux rien sur la sortie – Andromeda

+2

l'ai réparé ... en omettant simplement le tampon de sortie – Andromeda

+0

génial! excellent travail =) – mauris

0

Ce code,

<?php 

header('content-type: image/jpeg'); 
$src = $_GET['src']; 
$path = pathinfo($src); 
$watermark = imagecreatefrompng('watermark.png'); 
$watermark_width = imagesx($watermark); 
$watermark_height = imagesy($watermark); 
$image = imagecreatetruecolor($watermark_width, $watermark_height); 
if ($path['extension']=='png') 
$image = imagecreatefrompng($src); 
else if ($path['extension']=='jpg'||$path['extension']=='jpeg') 
$image = imagecreatefromjpeg($src); 
$size = getimagesize($_GET['src']); 
$dest_x = $size[0] - $watermark_width-10; 
$dest_y = $size[1] - $watermark_height-10; 
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 50); 
imagejpeg($image); 
imagedestroy($image); 
imagedestroy($watermark); 

?> 

Détails Ici, Image watermark in PHP