Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Creating a transparent embossed watermark image
Old 11-29-2005, 12:04 PM Creating a transparent embossed watermark image
Extreme Talker

Posts: 169
Trades: 0
can anyone have any idea on how to create a transparent embossed watermark image in php GD. The watermark image will be placed in the center of the image. And it should be transparent so that the watermark is filled with the image background.

I have a script to add watermark. But its not transparent. Your help will be extremely useful for me.

Thanks in advance.
john551 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-30-2005, 07:19 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Simple little script.

Requires a watermark images and an image to be water marked. Also needs php-gd.

PHP Code:
class water_mark {

    public static function 
apply($watermark$img) {

        
header('content-type: image/jpeg');

        
$watermark imagecreatefrompng($watermark);
        
$watermark_width imagesx($watermark);
        
$watermark_height imagesy($watermark);
        
$image imagecreatetruecolor($watermark_width$watermark_height);
        
$image imagecreatefromjpeg($img);
        
$size getimagesize($img);
        
$dest_x $size[0] - $watermark_width -5;
        
$dest_y $size[1] - $watermark_height -5;
        
imagecopymerge($image$watermark$dest_x$dest_y00$watermark_width$watermark_height100);
        
imagejpeg($image);
        
imagedestroy($image);
        
imagedestroy($watermark);
    }
}

water_mark::apply('watermark.jpg','tobemarked.jpg'); 
This currently just ouputs the image to the browser so if you wisj to link it into your document you would need to write your new image to dik.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf

Last edited by ibbo; 11-30-2005 at 07:35 AM..
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 11-30-2005, 07:34 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Modify
imagejpeg($image);
to
imagejpeg($image,'image.jpg', 99); (where 99 is the image quality) but it does not require the last param
and you can then
echo "<img src='image.jpg' >";

remeber to comment out the header if you go for this method.


FINALY

Use png transparent backgroung image for your watermark. GD has removed gif format functionality.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf

Last edited by ibbo; 11-30-2005 at 10:20 AM..
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 12-01-2005, 08:38 AM
Extreme Talker

Posts: 169
Trades: 0
Thanks for the code ibbo. But what I really want is an embossed image filled with the background image. Something similar to:-

http://www.codeguru.com/Cpp/G-M/bitm...icle.php/c1685

The above example is in C++. I want something similar in php.
__________________

Please login or register to view this content. Registration is FREE

TOP 10 WEB HOSTS COMPARED

BEST RESELLER HOSTING
john551 is offline
Reply With Quote
View Public Profile
 
Old 12-01-2005, 11:09 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Looks like your in luck.

PHP Code:
<?

class watermark {
   public static function 
emboss($pic1$patt) {

      
header("Content-type: image/png");
      
$source imagecreatefromjpeg($pic1); // Source
      
$pattern imagecreatefromjpeg($patt); // pattern

      
list ($width$height) = getimagesize($pic1);
      list (
$widthpatt$heightpatt) = getimagesize($patt);

      
$new_width $width;
      
$new_height $width $widthpatt $heightpatt;

      if (
$new_height $height) {
    
$offset intval(($new_height $height) / 2);
      }elseif (
$new_height $height) {
    
$offset intval(($new_height $height) / 2);
       } else {
       
$offset 0;
        }

    
$image_p imagecreatetruecolor($new_width$new_height);
    
$pattern imagecreatefromjpeg($patt);
     
imagecopyresampled($image_p$pattern0000$new_width$new_height$widthpatt$heightpatt);

    
$im imagecreatetruecolor($width$height);
        for (
$y 0$y $height$y ++) {
       for (
$x 0$x $width$x ++) {
         
$colors imagecolorsforindex($sourceimagecolorat($source$x$y));
         
$pattern_color imagecolorsforindex($image_pimagecolorat($image_p$x, ($y $offset)));
        
             
//changes brightness depending on luminance
        
if (($y $offset +1) > && ($y $offset) < ($new_height -1)) {
          
$brightness abs(($pattern_color['red'] * 50 255) - 50);
           if (
$pattern_color['red'] < 150) {
             
$change true;
           } else {
              
$change false;
              
$tally 0;
           }

           if (
$change && $tally 2) {
             
$highlight 1.8;
             
$tally ++;
           } else {
             
$highlight 1;
           }
           
$brightness $brightness $highlight;
        } else {
            
$brightness 0;
        }
        
$r = (($colors['red'] + $brightness) > 255) ? 255 : ($colors['red'] + $brightness);
        
$g = (($colors['green'] + $brightness) > 255) ? 255 : ($colors['green'] + $brightness);
        
$b = (($colors['blue'] + $brightness) > 255) ? 255 : ($colors['blue'] + $brightness);
        
$test imagecolorallocate($im$r$g$b);
        
imagesetpixel($im$x$y$test);
       }
        }

    
imagepng($im);
    
imagedestroy($im);
   }
}

watermark::emboss("apply-to-image.jpg""pattern.jpg");

?>
This works as you want, apply-to-image.jpg been the image you wish to embosse and pattern been the pattern you wish to embosse.

This is not my code I found it (you got me interested). I have tested it and it does embosse an image upon another image as your example looks.

The apply-to-image.jpg can be any image BUT the pattern image is simply black text upon a white background.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf

Last edited by ibbo; 12-01-2005 at 11:11 AM..
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 12-02-2005, 01:33 AM
Extreme Talker

Posts: 169
Trades: 0
Thank You very Very much Ibbo. That was exactly I was looking for. Thanks once again.
__________________

Please login or register to view this content. Registration is FREE

TOP 10 WEB HOSTS COMPARED

BEST RESELLER HOSTING
john551 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Creating a transparent embossed watermark image
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17127 seconds with 12 queries