SitePoint Sponsor

User Tag List

Page 3 of 6 FirstFirst 123456 LastLast
Results 51 to 75 of 138
  1. #51
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Brisbane, Australia
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Howdy,

    Fantastic script, thanks!

    tonywhite, by default you call it with watermark.php?src=car.jpg - see, 'SRC', not 'IMAGE'. Looks like a few other people had that problem also.


    I made an upgrade to the script to better suit my needs:
    I don't want to have to call the image like <img src="watermark.php?src=...."> - I would prefer to do a regular call.

    So, my server setup is this:
    Images get uploaded into a folder called 'upload_img'. Thumbnails are auto-generated on upload- same filename, just with a 'th_' prefix. I don't want to watermark the thumbnails. Here's what I did:

    Step 1: .htaccess
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_URI} upload_img(.*) [NC]
    RewriteRule ^(.*)$ http://www.domain.com/watermark.php?src=$1 [NC]
    This tells the server to direct any request for a file in the 'upload_img' folder through the watermark.php handler.

    Step 2: ignore th_ files
    Modify the php file to have an if/else statement using strpos for the filename. eg,
    Code:
    if (strpos contains 'th_') { 
       show raw image 
    } else { 
       run the script 
    }

    Tada!
    Now all my existing image calls still work without needing modification. I don't need to include 'watermark.php?src=...' in my <img> tags (so users can't view source to see what i'm doing). Public users simply CANNOT access the raw image without the watermark anymore (due to the .htaccess). And it leaves my thumbnails alone.

    Hope that helps someone.

  2. #52
    dutchie
    SitePoint Community Guest
    if you want the real name of your image use this, where $filename is the name of your image (get this from the GET string, but split this string when you use a full path)

    header("Content-type: image/jpeg;");
    header("Content-Disposition: filename= " . $filenaam);

  3. #53
    Theo
    SitePoint Community Guest
    What ever I try, it does not work. My code is okay, maybe a problem with the watermark.png... zip-file anyone ?

  4. #54
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trouble

    I only get to see an cann't display image icon in my browser

    http://www.ts-intermedia.nl/plaatje/index.html

    My code of index.html

    <img src="watermark.php?scr=1.jpg" />

    photo
    http://www.ts-intermedia.nl/plaatje/1.jpg

    watermark.png
    http://www.ts-intermedia.nl/plaatje/watermark.png

    I have GD 2.0.22

    Anyone ?

    (please post working Zip File, thanxs )

  5. #55
    SitePoint Zealot allstar's Avatar
    Join Date
    Sep 2005
    Location
    in my box.
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I find if you are going to create a png image with php's gd libary extension you should tell the browser that your creating a png image. Otherwise you might end up with something bad outputed. So, instead of doing image/jpeg as the header information do a image/png or an image/x-png. Also, I know that the gd libary can't change the file type of an image. If it is read in as a .png it will only be able to be outputed as a png, same with the other formats. I noticed the article said that *.gif support did not work in 2.0+ gd. Yes, it does work. It just doesn't support animated .gif files. It has to be static .gif files.
    Now, for a more robust error proof way of reading in the images then you should look towards checking the mime type of he image then do a switch or if then statements to set the proper imagecreatefrom* with the mime type of the image.

    I made comments to the listed code example. I know the comments and code isn't 100%, but correct me where you can and help out with this.

    name: watermark.php
    call by: watermark.php?photofile=name_of_png_image.png
    PHP Code:
    <?php
    /*
    orginal image need to be bigger then the watermark image
    orginal image and watermark image needs to be a .png file type
    Either a .htaccesss file or aphache has to be setup to output this .php file as a image file.
    */

    //read in the varibles from command line
    $photofile $_GET['photofile'];

    /* read the watermark image into memory. This would be a good place to detect the mime of the photofile and setup a switch to create the rigth type of image from it. */
    $watermark imagecreatefrompng('watermark.png');

    /* get the width and height of the watermark image. */
    list($watermark_width,$watermark_height) = getimagesize('watermark.png');

    /* read in the photofile into memory.  Another good place to setup a mime type switch to create the right image from the detected mime type. */
    $image imagecreatefrompng($photofile);

    /* this does the x,y position of the watermark need to cover the orginal image */
    list($img_w,$img_h) = getimagesize($photofile);
    $dest_x $img_w $watermark_width 5;
    $dest_y $img_h $watermark_height 5;

    /* save the transparentcy of the orginal image. */
    imagealphablending($imagefalse);
    imagesavealpha($image,true);

    /* copy the watermarked image onto the orginal image. */
    imagecopyresampled($image,$watermark,0,0,0,0,$dest_x,$dest_y,$watermark_width,$watermark_height);

    /* output the image.  Great place to setup a mime switch to output the correct content type message */
    header("Content-Type: image/png");
    header("Content-Disposition: filename= " $photofile);
    imagepng($image);

    //free up the memory used
    imagedestroy($image);
    imagedestroy($watermark);
    ?>

  6. #56
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    allstar .....Correct me if I am wrong.... but I can not use a PNG watermark with JPG files ?

    When I use your code and I use a PNG watermark and a PNG photo... then it works....

    But I do want to use JPG files.

    Well still like to get working files (incl watermark.png and jpg) in zipped file

  7. #57
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guys .... don't ask me why... but I've got it working !!

    Thanxs for all the help !

    T

  8. #58
    SitePoint Zealot allstar's Avatar
    Join Date
    Sep 2005
    Location
    in my box.
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tvds
    allstar .....Correct me if I am wrong.... but I can not use a PNG watermark with JPG files ?

    When I use your code and I use a PNG watermark and a PNG photo... then it works....

    But I do want to use JPG files.

    Well still like to get working files (incl watermark.png and jpg) in zipped file
    That is why I said to use a switch to detect what the mime types of the files are. .jpg files are not made to be transparent like .png/.gif files are. So, your watermark is going to have the black stuff to it. If your orginal file was a .jpg and your watermark is a .png/.gif then it would work, because the .png can have transparent parts to it. Though the final image will not, because it will be a .jpg file. The example is just the basic structure to do the task for .png files.

  9. #59
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For PNG24 alpha transparency, use imagecopy() instead (take out the last pct argument though)

  10. #60
    David A. Gaitros
    SitePoint Community Guest
    Very nice feature. However I found the ability to display the image using the imagejpeg() directly to the web very limiting due to the restriction that the header must be modified for image/jpeg only. Any attempt to display something other then the image before resulted in just the text string being displayed. I have semi comlex annotation software where I need to temporarily overlay arrow and text objects on a biological image. The imagecopymerge() function worked quite nicely and efficienty however I had to write image out to a file using the imagejpeg() function before using the <img src html function. If there are any ways around this I would like to know.

  11. #61
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a way to save the watermarked $image to a file? I tried using fopen and fwrite, but they didn't work.

  12. #62
    SitePoint Member
    Join Date
    Aug 2005
    Location
    United Kingdom
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're using a png 24 using alpha transparency for your watermark image (e.g. open new file in photoshop, type "COPYRIGHT MESSAGE", drop the opacity by about 50% and "save for web" using png24 and saving transparency vaules), you might want to put the watermark in the middle of the image.

    To put the watermark slap bang in the middle of the image . . . this should work:

    $dest_x = ($size[0] / 2) - ($watermark_width / 2);
    $dest_y = ($size[1] / 2) - ($watermark_height / 2);

    ($size[0] / 2) and ($size[1] / 2) will find the "dead center" of the image to be watermarked which would place the watermark's top left corner in the center of the screen. To shift the watermark left and up we just work out half of the watermarks width and height then subtract it from the "dead center" calculation.


  13. #63
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ajferg
    Howdy,

    Fantastic script, thanks!

    tonywhite, by default you call it with watermark.php?src=car.jpg - see, 'SRC', not 'IMAGE'. Looks like a few other people had that problem also.


    I made an upgrade to the script to better suit my needs:
    I don't want to have to call the image like <img src="watermark.php?src=...."> - I would prefer to do a regular call.

    So, my server setup is this:
    Images get uploaded into a folder called 'upload_img'. Thumbnails are auto-generated on upload- same filename, just with a 'th_' prefix. I don't want to watermark the thumbnails. Here's what I did:

    Step 1: .htaccess
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_URI} upload_img(.*) [NC]
    RewriteRule ^(.*)$ http://www.domain.com/watermark.php?src=$1 [NC]
    This tells the server to direct any request for a file in the 'upload_img' folder through the watermark.php handler.

    Step 2: ignore th_ files
    Modify the php file to have an if/else statement using strpos for the filename. eg,
    Code:
    if (strpos contains 'th_') { 
       show raw image 
    } else { 
       run the script 
    }

    Tada!
    Now all my existing image calls still work without needing modification. I don't need to include 'watermark.php?src=...' in my <img> tags (so users can't view source to see what i'm doing). Public users simply CANNOT access the raw image without the watermark anymore (due to the .htaccess). And it leaves my thumbnails alone.

    Hope that helps someone.

    I am trying to use this cool code in my .htaccess file, but my server keeps giving me back Http Error 500.

    Would you kindly explain how I could get this to work? I have a bunch of listings on eBay and would like to watermark all the images.

    Thanks!

  14. #64
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nevermind, got it sorted...the problem was that I had put all the files in my images directory. Moved them to root and we are good to go.

    Thanks all!

  15. #65
    tijuan
    SitePoint Community Guest
    i would recommend "imagecopyresampled" function rather than "imagecopymerge" when using transparent png.

  16. #66
    Twitter - @CarlBeckel busy's Avatar
    Join Date
    May 2004
    Location
    Richmond, VA, USA
    Posts
    819
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, if you are using imagecopyresampled to resize a watermark with transparency, (so it will fit your image better) it will become opaque. There is a workaround for this located here
    Last edited by busy; Mar 29, 2006 at 04:24. Reason: Fixed the link

  17. #67
    Faheem
    SitePoint Community Guest
    this code isnt working.. problem is in header.. i dont know why... if any one know do help me in this regard.


  18. #68
    anton
    SitePoint Community Guest
    if you copy & paste this code, it's unlikely to work, because of tabs, spaces at ends of lines, etc. better to retype it. in particular, if the content-type header winds up with a tab instead of a space, it won't be recognized.

  19. #69
    Jyotsna
    SitePoint Community Guest
    Hi All!
    Please help me out. I am able to create image with watermark. But I am not able to copy that image into some other location. It is just displaying in the browser.

    Thanks in Advance.
    Jyotsna. Ch.

  20. #70
    Matthew Alberty
    SitePoint Community Guest
    This code does not work for me either. Maybe it is a permissions issue. Hmm...

  21. #71
    Stephen Carter
    SitePoint Community Guest
    Codes working fine in IE6 but not in Firefox 1.5.0.4 - any ideas?

  22. #72
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I don't kown why ?

    Quote Originally Posted by Claudio Heidel
    I fix it to run with transparent watermarks

    <?php
    header('content-type: image/jpeg');
    $watermark = imagecreatefrompng('watermark.png');
    $watermark_width = imagesx($watermark);
    $watermark_height = imagesy($watermark);
    $image = imagecreatetruecolor($watermark_width, $watermark_height);
    $image = imagecreatefromjpeg($_GET['photo_file']);
    $size = getimagesize($_GET['photo_file']);
    $dest_x = $size[0] - $watermark_width - 5;
    $dest_y = $size[1] - $watermark_height - 5;
    imagecopy($image, $watermark, $dest_x , $dest_y, 0, 0, $watermark_width, $watermark_height);
    imagejpeg($image);
    imagedestroy($image);
    imagedestroy($watermark);
    ?>

    Claudio Heidel
    www.heidel.com.ar


    When I use this code (at upon) for a php file. When run it error :

    <br />
    <b>Warning</b>: imagecopy(): supplied argument is not a valid Image resource in <b>c:\appserv\www\ch15\duc.php</b> on line <b>11</b><br />
    <br />
    <b>Warning</b>: imagejpeg(): supplied argument is not a valid Image resource in <b>c:\appserv\www\ch15\duc.php</b> on line <b>12</b><br />
    <br />
    <b>Warning</b>: imagedestroy(): supplied argument is not a valid Image resource in <b>c:\appserv\www\ch15\duc.php</b> on line <b>13</b><br />


    Why ? Please help me.
    Many Thanks

  23. #73
    Artur
    SitePoint Community Guest
    rwduc: You do not have gd library

  24. #74
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok ! I have used it. But why I use "Watermark" is PNG file but it is opaque.
    Plz help me !
    Thanks.

  25. #75
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Artur
    rwduc: You do not have gd library
    Thank you very much

    But, same i said : when i use "png" image for watermark it is not tran


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •