Author Topic: watermark when showing pic  (Read 54205 times)

0 Members and 1 Guest are viewing this topic.

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
watermark when showing pic
« on: April 29, 2005, 08:37:18 PM »
hi there! :P

I'm trying 4images and i want to put a watermark in the pics, i saw in this topic: http://www.4homepages.de/forum/index.php?topic=3808.00 but it is not what i really want in fact, 'cos it aplies the mark when uploading the pics, but i want to geta watermarked image only when showing the pic, so the original is not changed at all.

I have a php file which inserts a watermark on every image, and it can be access like an image itself... let me explain, the file is named watermark.php and the code is:

Code: [Select]
<?php

$image 
$_GET['get_image'];
$watermark "water.png";

$im imagecreatefrompng($watermark);

$ext substr($image, -3);


if(
strtolower($ext) == "gif") {
    if (!
$im2 imagecreatefromgif($image)) {
        echo 
"Error opening $image!"; exit;
    }
} else if(
strtolower($ext) == "jpg") {
    if (!
$im2 imagecreatefromjpeg($image)) {
        echo 
"Error opening $image!"; exit;
    }
} else if(
strtolower($ext) == "png") {
    if (!
$im2 imagecreatefrompng($image)) {
        echo 
"Error opening $image!"; exit;
    }
} else {
    die;
}

imagecopy($im2$im, (imagesx($im2)/100)-(imagesx($im)/100), (imagesy($im2)/100)-(imagesy($im)/100), 00imagesx($im), imagesy($im));

if(
$_GET[repeat]) {
    
$waterless imagesx($im2) - imagesx($im);
    
$rest ceil($waterless/imagesx($im)/1);
    
    for(
$n=1$n<=$rest$n++) {
        
imagecopy($im2$im, ((imagesx($im2)/100)-(imagesx($im)/100))-(imagesx($im)*$n), (imagesy($im2)/100)-(imagesy($im)/100), 00imagesx($im), imagesy($im));
        
imagecopy($im2$im, ((imagesx($im2)/100)-(imagesx($im)/100))+(imagesx($im)*$n), (imagesy($im2)/100)-(imagesy($im)/100), 00imagesx($im), imagesy($im));
    }
}

header("Content-Type: image/jpeg");
imagejpeg($im2);
imagedestroy($im);
imagedestroy($im2);

?>

Let's see: suposse i have another page called show.html, which shows the picture. This page is in the folder /images/, just as watermark.php (they both are in the same path /images/) and if I try to show a pic in the folder /images/pics/cat1/pic.jpg the code would be:

Code: [Select]
<img src="watermark.php?get_image=images/pics/cat1/pic.jpg">instead of
Code: [Select]
<img src="images/pics/cat1/pic.jpg">
SO, my question is how to do it in 4images, what should i change... i have already look for tha code that shows the image in the file details.php, so i can change it, but i find nothing... how am i supossed to do it?

thanks a lot

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: watermark when showing pic
« Reply #1 on: April 29, 2005, 11:11:57 PM »
did u try add in jpg.html template:
Code: [Select]
<img src="watermark.php?get_image={media_src}"> ? (make sure watermark.php is located in 4images root directory.)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #2 on: May 01, 2005, 03:37:30 AM »
thanks for that, i got what i wanted.

2 more questions  :lol: (forgive my bad english.. i'm a spanish speaker):

1. And how can i do the same thing when downloading the file by pressing the download buttons (as jpg or as zip)? i mean, download the marked pic instead of the original?

2. If a user see the source code will find the pic easily... what i want to do is to set in the file watermark.php a "secret" folder...  :? ill explain: I have my data folder (and of course all the pics) into anoher one called hideimagesfromuser/ (it's just a name), so when the jpg.html file calls the media_src the folder shown is hideimagesfromuser/data/media/004/001.jpg... well i want to do in fact is to create one more variable to write instead of media_src to not show the full directory, fore example only media/004/001.jpg, and the rest is given by the file watermark.php but not shown... (i hope you did understand.... xoxo my english is so bad :P)

Just one more... I wonder if it is possible to restrict the access to the folder hideimagesfromuser/data/media/ and all the subfolders in there to the users who try to enter directly to one file in this folder... i read that i could do it by using a .htaccess file... but i dont even know it... thanks again and i hope for some help... greets!

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: watermark when showing pic
« Reply #3 on: May 01, 2005, 05:08:11 AM »
2. If a user see the source code will find the pic easily... what i want to do is to set in the file watermark.php a "secret" folder... :? ill explain: I have my data folder (and of course all the pics) into anoher one called hideimagesfromuser/ (it's just a name), so when the jpg.html file calls the media_src the folder shown is hideimagesfromuser/data/media/004/001.jpg... well i want to do in fact is to create one more variable to write instead of media_src to not show the full directory, fore example only media/004/001.jpg, and the rest is given by the file watermark.php but not shown... (i hope you did understand.... xoxo my english is so bad :P)

Just one more... I wonder if it is possible to restrict the access to the folder hideimagesfromuser/data/media/ and all the subfolders in there to the users who try to enter directly to one file in this folder... i read that i could do it by using a .htaccess file... but i dont even know it... thanks again and i hope for some help... greets!
1) we have a very usefull topic Pic Security u might want to check it out ;)

here is your modifyed watermark script:
Code: [Select]
<?php
$nozip 
1;
define('ROOT_PATH''./');
define('GET_CACHES'1);
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
//$user_access = get_permission();

$watermark "water.png";

if (!
$image_id)
{
  die("Security violation");
}

$sql "SELECT cat_id, image_media_file, image_thumb_file
        FROM "
.IMAGES_TABLE."
        WHERE image_id = 
$image_id";
$image_row $site_db->query_firstrow($sql);
$cat_id = (isset($image_row['cat_id'])) ? $image_row['cat_id'] : 0;

if (!
check_permission("auth_viewcat"$cat_id) || !check_permission("auth_viewimage"$cat_id) || !$image_row)
{
  die("No permission");
}

$im imagecreatefrompng($watermark);

$image MEDIA_PATH."/".$cat_id."/".$image_row['image_media_file'];
$types = array(=> "gif"=> "jpeg"=> "png");
if (
$image_info = @getimagesize($image))
{
  $image_create_handle "imagecreatefrom".$types[$image_info[2]];
  if (!$im2 = @$image_create_handle($image))
  {
    die("Error opening $image!");
  }

  imagecopy($im2$im, (imagesx($im2)/100)-(imagesx($im)/100), (imagesy($im2)/100)-(imagesy($im)/100), 00imagesx($im), imagesy($im));
  
  
if($_GET[repeat])
  {
    $waterless imagesx($im2) - imagesx($im);
    $rest ceil($waterless/imagesx($im)/1);
    
    
for($n=1$n<=$rest$n++)
    {
      imagecopy($im2$im, ((imagesx($im2)/100)-(imagesx($im)/100))-(imagesx($im)*$n), (imagesy($im2)/100)-(imagesy($im)/100), 00imagesx($im), imagesy($im));
      imagecopy($im2$im, ((imagesx($im2)/100)-(imagesx($im)/100))+(imagesx($im)*$n), (imagesy($im2)/100)-(imagesy($im)/100), 00imagesx($im), imagesy($im));
    }
  }
  
  header
("Content-Type: image/jpeg");
  imagejpeg($im2);
  imagedestroy($im);
  imagedestroy($im2);
}
else
{
  die("Error opening $image!");
}
  
?>
and jpg.html template:
Code: [Select]
<img src="watermark.php?image_id={image_id}">no more showing the images path.
but I must warn u, this version will much slower then yours.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #4 on: May 01, 2005, 05:44:48 AM »
well thanks again... i've done it! works fine too!, but there's something you missed... when pressing the download and download as zip buttons, it is the original pic the one downloaded, not the marked one. Is there anyway to download the marked one? i know that when uploading the pics i can put the download dir, but i cannot do that with all the pics, it would last a whole life to have it done, so...

Or maybe it is not possible, in that case (but only in that case) how can i delete the download buttons and remove the copyright notice shown in the rightclick? so the user can save the image as usual, but it goes with the mark.

Thanks

P.D.: I'm starter in this stuff  :lol:... can i change the thumbnails directory even if the gallery have already been installed? i know i have to modify the constants.php file, but this will not make the gallery work wrong right? Thanks

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: watermark when showing pic
« Reply #5 on: May 01, 2005, 06:24:59 AM »
well thanks again... i've done it! works fine too!, but there's something you missed... when pressing the download and download as zip buttons, it is the original pic the one downloaded, not the marked one. Is there anyway to download the marked one? i know that when uploading the pics i can put the download dir, but i cannot do that with all the pics, it would last a whole life to have it done, so...
ofcourse its possible ;), but it would require havy modifications in download.php...sorry, u are on your own there.

Or maybe it is not possible, in that case (but only in that case) how can i delete the download buttons and remove the copyright notice shown in the rightclick? so the user can save the image as usual, but it goes with the mark.
FAQ: Remove the right-click disabler


P.D.: I'm starter in this stuff :lol:... can i change the thumbnails directory even if the gallery have already been installed? i know i have to modify the constants.php file, but this will not make the gallery work wrong right? Thanks
it will work just fine. 4images does not store the full path to the images in the database, only filenames and calculating the path to the images when they are being requested.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: watermark when showing pic
« Reply #6 on: May 01, 2005, 06:33:24 AM »
hmmm...I just got an idea about download thingie...
what if u rename in download.php
Code: [Select]
function get_file_data($file_path) {to function get_file_data2($file_path) {
and above that line add this:
Code: [Select]
function get_file_data($image)
{
  $types = array(1 => "gif", 2 => "jpeg", 3 => "png");
  if ($image_info = @getimagesize($image))
  {
    $image_create_handle = "imagecreatefrom".$types[$image_info[2]];
    if (!$im2 = @$image_create_handle($image))
    {
      die("Error opening $image!");
    }
 
    imagecopy($im2, $im, (imagesx($im2)/100)-(imagesx($im)/100), (imagesy($im2)/100)-(imagesy($im)/100), 0, 0, imagesx($im), imagesy($im));
   
    if($_GET[repeat])
    {
      $waterless = imagesx($im2) - imagesx($im);
      $rest = ceil($waterless/imagesx($im)/1);
     
      for($n=1; $n<=$rest; $n++)
      {
        imagecopy($im2, $im, ((imagesx($im2)/100)-(imagesx($im)/100))-(imagesx($im)*$n), (imagesy($im2)/100)-(imagesy($im)/100), 0, 0, imagesx($im), imagesy($im));
        imagecopy($im2, $im, ((imagesx($im2)/100)-(imagesx($im)/100))+(imagesx($im)*$n), (imagesy($im2)/100)-(imagesy($im)/100), 0, 0, imagesx($im), imagesy($im));
      }
    }
    ob_start();
    @ob_implicit_flush(0);
    imagejpeg($im2);
    $file_data = ob_get_contents();
    ob_end_clean();
    imagedestroy($im);
    imagedestroy($im2);
    return $file_data;
  }
  else
  {
    return get_file_data2($image);
  }
}

:?:
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #7 on: May 01, 2005, 09:34:25 PM »
hi, i have fixed the problem when downloading the pic, thnks for that, now i have discovered another problem, i didn't notice that because i was trying with only one pic, but now i added others,and it does not works good. It's about the watermark.php file... Lets suposse i want to view the pic 001.jpg, i open it and everything is normal. But if i want to see the next picture, or any other, and click in the thumbnail, the details.php page shows the same first pic (001.jpg), everything esle, like the name of the pic, the comments and the stats of the image are normal, even the size of the image is correct, but the pic itself is wrong. it seems the watermark.php file is not reloaded when seeing other pictures  :cry:  can you help me with this? please?

thanks u very much

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: watermark when showing pic
« Reply #8 on: May 01, 2005, 09:50:33 PM »
what is that path to the "image" u see? (either look in the source, or right click on the image -> properties)
can I see it in action?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #9 on: May 01, 2005, 10:12:48 PM »
the path of the image is:

when seeing the first: watermark.php?repeat=1&image_id=1 and the sorce code is:

Code: [Select]
<img src="watermark.php?repeat=1&image_id=1" border="1" alt="001" width="361" height="540" />
and the second: watermark.php?repeat=1&image_id=2

Code: [Select]
<img src="watermark.php?repeat=1&image_id=2" border="1" alt="002" width="361" height="540" />
as u can c both codes are almost the same, so the problem is in the file watermark.php (the source code is the one you gave me before)... how can i solve this? thanks

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: watermark when showing pic
« Reply #10 on: May 01, 2005, 10:56:48 PM »
the only explanation I have is that your browser some how caching the first image and use the cache for the second image...
anyway, can I see it in action?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #11 on: May 01, 2005, 11:05:41 PM »
wait on.... the problem is in the code i think, cuz i've notice something else, the pic shown is the same of the thumbnail shown as the random pic, so the problem must be in the source code of watermark.php... can you review it pleaze? thanks

if u find no mistake, i gill give the url i'm working on

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: watermark when showing pic
« Reply #12 on: May 01, 2005, 11:24:51 PM »
that's it, that's the problem.
ok, in includes/functions.php find:
Code: [Select]
      "image_name" => $image_name,Insert below:
Code: [Select]
      "image_id" => $image_id,
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #13 on: May 01, 2005, 11:58:15 PM »
good! it is working well now. Thanks for all...

by the way, the download.php mod you gave me didnt work, but that's ok. I removed the download buttons

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #14 on: May 26, 2005, 03:45:49 AM »
well its a long time since my last post on this topic, but there's always something that does not work fine. All's fine with the watermark mod you gave me, but the pic is not shown in the e-cards. I mean, if i try to send the pic as an ecard, the person i sent it to cannot see the pic in the card... why is that?