Pogledajte određenu poruku
Staro 06. 07. 2009.   #7
bluesman
Goran Pilipović
Sir Write-a-Lot
 
Avatar bluesman
 
Datum učlanjenja: 18.05.2005
Lokacija: Beograd
Poruke: 5.450
Hvala: 288
1.247 "Hvala" u 446 poruka
bluesman je osoba koju treba slušatibluesman je osoba koju treba slušatibluesman je osoba koju treba slušatibluesman je osoba koju treba slušatibluesman je osoba koju treba slušatibluesman je osoba koju treba slušatibluesman je osoba koju treba slušatibluesman je osoba koju treba slušatibluesman je osoba koju treba slušati
Pošaljite ICQ poruku za bluesman
Default

Koristi funkciju imagecopymerge().

Evo jedna stara funkcija koja je radila super, ubacivala je watermark dole levo i daje mu opacity koji navedes (default 70%) ali to moze lako da se promeni.

PHP kôd:
/**
 * Embed watermark on image
 * if you don't enter destination image, it will overwrite the source image
 *
 * @param string $watermark_filename - path to image to be used as watermark
 * @param string $source_filename - path to source image
 * @param string $dest_filename - path to destination image
 * @param int $blending - watermark opacity
 * @returns int -1 (error) | 0 (warning) | 1 (ok)
 */

function embedWatermark ($watermark_filename$source_filename$dest_filename ""$blending 70)
{
    
$source_img    = !empty($source_filename)    ? trim($source_filename) : "";
    
$watermark    = !empty($watermark_filename)    ? trim($watermark_filename) : "";
    
$target_img    = !empty($dest_filename)    ? trim($dest_filename)    : "";
    
$blending    intval($blending);

    if (
$blending || $blending 100)    { $blending 70; }

    if (empty(
$source_img))        { return addError(__FUNCTION__." Source file not specified!"); }
    if (!
is_file($source_img))    { return addError(__FUNCTION__." Source file "$source_img" not found!"); }
    if (empty(
$watermark))        { return addError(__FUNCTION__." watermark file not specified!"); }
    if (!
is_file($watermark))    { return addError(__FUNCTION__." watermark file "$watermark" not found!"); }
    if (empty(
$target_img))        { $target_img $source_img; }

    
$source_size    getimagesize($source_img);
    
$watermark_size getimagesize($watermark);

    
$src_w         = !empty($source_size[0]) ? $source_size[0] : 1;
    
$src_h         = !empty($source_size[1]) ? $source_size[1] : 1;
    
$src_type     = !empty($source_size[2]) ? $source_size[2] : TYPE_JPG;
    
$wmk_w         = !empty($watermark_size[0]) ? $watermark_size[0] : 1;
    
$wmk_h         = !empty($watermark_size[1]) ? $watermark_size[1] : 1;
    
$wmk_type     = !empty($watermark_size[2]) ? $watermark_size[2] : TYPE_JPG;

    if     (
$src_type == TYPE_JPG)    { $src imagecreatefromjpeg ($source_img); }
    elseif (
$src_type == TYPE_GIF)    { $src imagecreatefromgif ($source_img); }
    elseif (
$src_type == TYPE_PNG)    { $src imagecreatefrompng ($source_img); }
    else                { return 
addError(__FUNCTION__." unknown image type"); }

    if (!
$src)    // if failed?
    
{
        return 
addError(__FUNCTION__." GD source image create failed");
    }

    if     (
$wmk_type == TYPE_JPG)    { $wmk imagecreatefromjpeg ($watermark); }
    elseif (
$wmk_type == TYPE_GIF)    { $wmk imagecreatefromgif ($watermark); }
    elseif (
$wmk_type == TYPE_PNG)    { $wmk imagecreatefrompng ($watermark); }
    else                 { return 
addError(__FUNCTION__." Unknown watermark image type "); }

    if (!
$wmk)    // if failed?
    
{
        return 
addError(__FUNCTION__." GD watermark create failed");
    }

    
// set the watermark position (bottom left)
    
$position_x 0// $src_w - $wmk_w;
    
$position_y $src_h $wmk_h;

    
// set destination image size propotional as source image file
    
$dst imagecreatetruecolor($src_w$src_h);

    
// copy image first
    
imagecopy ($dst$src0000$src_w$src_h);

    
// copy watermark after
    
imagecopymerge ($dst$wmk$position_x$position_y00$wmk_w$wmk_h$blending);

    
// create file on disk
    
if     ($src_type == TYPE_GIF)    { imagegif ($dst$target_img); }
    elseif (
$src_type == TYPE_PNG)    { imagepng ($dst$target_img); }
    else                { 
imagejpeg($dst$target_img); }

    
imagedestroy($dst);
    
imagedestroy($src);
    
imagedestroy($wmk);
    return 
1;    // ok

__________________
Goran Pilipović a.k.a. Ugly Fingers Bradley f.k.a. bluesman
I don't always know what I'm talking about but I know I'm right!
bluesman je offline   Odgovorite uz citat