4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: okram on April 29, 2005, 08:37:18 PM

Title: watermark when showing pic
Post by: okram 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
Title: Re: watermark when showing pic
Post by: V@no 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.)
Title: Re: watermark when showing pic
Post by: okram 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!
Title: Re: watermark when showing pic
Post by: V@no 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.
Title: Re: watermark when showing pic
Post by: okram 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
Title: Re: watermark when showing pic
Post by: V@no 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 (http://www.4homepages.de/forum/index.php?topic=3088)


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.
Title: Re: watermark when showing pic
Post by: V@no 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);
  }
}

:?:
Title: Re: watermark when showing pic
Post by: okram 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
Title: Re: watermark when showing pic
Post by: V@no 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?
Title: Re: watermark when showing pic
Post by: okram 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
Title: Re: watermark when showing pic
Post by: V@no 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?
Title: Re: watermark when showing pic
Post by: okram 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
Title: Re: watermark when showing pic
Post by: V@no 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,
Title: Re: watermark when showing pic
Post by: okram 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
Title: Re: watermark when showing pic
Post by: okram 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?
Title: Re: watermark when showing pic
Post by: V@no on May 26, 2005, 05:45:33 AM
not showing as what? as a broken image or no image at all?
if its a broken image (red x) then what is the path to it in the page source?
Title: Re: watermark when showing pic
Post by: okram on May 26, 2005, 01:18:53 PM
well i think i should remove this lines from the watermark.php

Code: [Select]
if (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id) || !$image_row)
{
  die("No permission");
}

in that way it workks correctly..... id it good?

thanks
Title: Re: watermark when showing pic
Post by: triaphoto on May 27, 2005, 09:46:56 PM
nice idea!

maybe its a little bit off topic but i think your pictures will suffer a certain loss of quality by watermarking them "on the fly".

the best workflow is:
1. open the picture in original size
2. reduce the size
3. watermark it
4. save it.

never save between step 2 and 3, close the picture and open it again.
So I think its a better idea to upload the unmarked AND the watermarked picture. Or to upload a picture a little bit bigger in size than the output and add an additional command "reduce size" before watermarking the picture.

 

 
Title: Re: watermark when showing pic
Post by: okram on May 28, 2005, 02:18:33 AM
Quote
maybe its a little bit off topic but i think your pictures will suffer a certain loss of quality by watermarking them "on the fly".
well i'm using this method and the watermarked pictures are as good as the original ones...
Quote
the best workflow is:
1. open the picture in original size
2. reduce the size
3. watermark it
4. save it.

never save between step 2 and 3, close the picture and open it again.
So I think its a better idea to upload the unmarked AND the watermarked picture. Or to upload a picture a little bit bigger in size than the output and add an additional command "reduce size" before watermarking the picture.

could you explain it a bit better? i did not understand  :lol:

greets  8)
Title: Re: watermark when showing pic
Post by: triaphoto on May 28, 2005, 06:07:28 PM
ok no prob:
every time you save a jpeg-picture this results in a certain loss of quality.

so if you have to modify a picture NEVER:
save between the steps
close the picture
and open the partially modified picture again to go on with the modification.

for example: by saving the picture you get a quality loss of 10%

if you save the picture AFTER the complete workflow: 10%
if you save it, close it  and reopen it DURING the workflow: 20%

the effect is similar when you use a graphic library.

edit: its no problem if you just save it during the workflow without closing and reopening, because the image is still in your memory
 
Title: Re: watermark when showing pic
Post by: okram on May 28, 2005, 08:59:22 PM
yep, perhaps you're right, but like i said, my pics don't lose their quality at all when watermarking them, and if it does, it can't be more than 1 or 2 % cuz they look just as the original ones... (no better, no worse)

Greets
Title: Re: watermark when showing pic
Post by: ch€ri{Bi}² on August 17, 2005, 01:59:03 PM
thanks for this...
I use watermark on the fly for some time  8)   and the process works well, why not to move him towards the Mods & Plugins (Publishing & Support) forum?  :wink:

my question :  :?: How may I prevent the direct access to the watermark.php file? (for the moment when you call : http://your.domain.net/4images/watermark.php?image_id=xxx    :arrow: it shows 1 watermark pic)
i think about a line of code at the top of the watermark.php file to verifiy if the access is direct or from a file...

Regards.
Title: Re: watermark when showing pic
Post by: okram on September 10, 2005, 06:03:21 AM
thanks for this...
I use watermark on the fly for some time  8)   and the process works well, why not to move him towards the Mods & Plugins (Publishing & Support) forum?  :wink:
yeah... that would be great  :lol:

How may I prevent the direct access to the watermark.php file? (for the moment when you call : http://your.domain.net/4images/watermark.php?image_id=xxx    :arrow: it shows 1 watermark pic)
i think about a line of code at the top of the watermark.php file to verifiy if the access is direct or from a file...
I've been using sessions to solve this... here's the solution:

File page_header.php in includes folder:
Add this line somewhere at the beginning of the page_header.php file... I put it before $total_images = 0;
Code: [Select]
$_SESSION['_access_is_correct']="y";As far as I could see, page_header.php is included in every page of the gallery, so what we do here is just registering a new session variable -> $_SESSION['_access_is_correct']... It doesn't mind the value you gave to it...

File watermark.php at the main root:
Well the final code would be like this:
watermark.php
Code: [Select]
<?php
$nozip 
1;
$image_id $_GET['image_id'];
define('ROOT_PATH''./');
define('GET_CACHES'1);
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
$user_access get_permission();

//here we check if our session variable is set... 
//if it's not, the pic is not shown
if(!isset($_SESSION['_access_is_correct']))
  {
  die("You are not allowed to see this page");
  }
else 
  {
  
//if the variable is set, it means the user is accessing 
  //the image correctly, then we show it.
  //but before showing the pic, we unset our variable for security reasons
  $_SESSION['_access_is_correct']="";
  unset($_SESSION['_access_is_correct']);

$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;

$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));
  
    $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!");
$_SESSION['_access_is_correct']="";
unset(
$_SESSION['_access_is_correct']);
}
  
  
}
?>

Try it, and if you have any problems, post a new msg here

Best regards
Title: Re: watermark when showing pic
Post by: Xyu BAM on September 10, 2005, 06:18:47 AM
@okram:
better yet store time() in that session so it can expired in, let say, 1 minute after any page was opened.
Title: Re: watermark when showing pic
Post by: okram on September 12, 2005, 05:25:47 AM
I really prefer unsetting the variable before showing the image...

If you set a life time for the session, 4example 1 minute, so the visitor will be able to access the watermark.php file during all that time... and what we're trying to prevent is the direct access to this file at anytime or anyway...

I think its much better if we unset our variable once we've checked that it exists and that the visitor is accessing the picture correctly...

Regards
Title: Re: watermark when showing pic
Post by: impss on September 13, 2005, 11:51:30 PM
Can anyone help?

I use this Modification , but when someone tries to directlink it onto another forum
you get a

Sorry, dynamic pages in the [IMG] tags are not allowed

Is there anyway to fix it so it would work?

thanks for anyhelp
Title: Re: watermark when showing pic
Post by: okram on September 14, 2005, 01:30:41 AM
I'm afraid you can't do nothing about that... If that other forum does not allow dynamic pages in its [IMG] tags, so whatever you do with your watermark.php code will not change that... watermark.php is a dynamic file, and that's why we use it to watermark serveral different pictures...

Quote
when someone tries to directlink it onto another forum
you get a

Sorry, dynamic pages in the [IMG] tags are not allowed
can i see that other forum you mentioned? can you post the url plz???

Best regards
Title: Re: watermark when showing pic
Post by: TheOracle on September 14, 2005, 01:34:08 AM
well i think i should remove this lines from the watermark.php

Code: [Select]
if (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id) || !$image_row)
{
  die("No permission");
}

in that way it workks correctly..... id it good?

thanks

Rather than removing it, if you replace it

with :

Code: [Select]

if (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id) || !$image_row) {

show_error_page($lang['no_permission']);

} ###### End of if statement.


Will it work ? ;)

As for this line :

Quote

$types = array(1 => "gif", 2 => "jpeg", 3 => "png");


it could always be

replaced with :

Code: [Select]

$types = str_replace(",",", ",$config['allowed_mediatypes']);


;)

As for this one :

Quote

if (!$im2 = @$image_create_handle($image))
  {
    die("Error opening $image!");
  }


replace with :

Code: [Select]

if (!$im2 = @$image_create_handle($image)) {

show_error_page($lang['no_image_found']);

} ###### End of if statement.


;)
Title: Re: watermark when showing pic
Post by: okram on September 14, 2005, 01:42:32 AM
How may I prevent the direct access to the watermark.php file? (for the moment when you call : http://your.domain.net/4images/watermark.php?image_id=xxx    :arrow: it shows 1 watermark pic)
i think about a line of code at the top of the watermark.php file to verifiy if the access is direct or from a file...
I was forgetting somethign in the mod i posted to solve that problem... In the page_footer.php file we need to add this line:
Code: [Select]
// This is necessary in case user did not see any picture in a page,
// and due to that, our session variable is still active and exists
if(isset($_SESSION['_access_is_correct']))
{
unset($_SESSION['_access_is_correct']);
}

Regards
Title: Re: watermark when showing pic
Post by: impss on September 14, 2005, 01:44:41 AM
I figured that was the case  :?

this is the forum the gives me that error, http://www.inegma.net/mb/index.php?act=?

and another one i use just gives me a red x - http://www.impalasuperstore.com/naisso/Forum2005/



I dont use this script to watermark the pics on my site, I allow members to use the pictures on the forums by protecting the actuall image and giving them a link that uses the watermark script.

My only option might be to try to fgure out how to use .htaccess for leeched images to watermark the pictures. but as of yet, i havent been able to figure that out.

the image works on this forum though
(http://www.cusstom.com/gallery/img.php?get_image=./data/media/20/103-0301_IMG.jpg)
Title: Re: watermark when showing pic
Post by: okram on September 14, 2005, 01:46:06 AM
well i think i should remove this lines from the watermark.php

Code: [Select]
if (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id) || !$image_row)
{
  die("No permission");
}

in that way it workks correctly..... id it good?

thanks

Rather than removing it, if you replace it

with :

Code: [Select]

if (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id) || !$image_row) {

show_error_page($lang['no_permission']);

} ###### End of if statement.


Will it work ? ;)

As for this line :

Quote

$types = array(1 => "gif", 2 => "jpeg", 3 => "png");


it could always be

replaced with :

Code: [Select]

$types = str_replace(",",", ",$config['allowed_mediatypes']);


;)

As for this one :

Quote

if (!$im2 = @$image_create_handle($image))
  {
    die("Error opening $image!");
  }


replace with :

Code: [Select]

if (!$im2 = @$image_create_handle($image)) {

show_error_page($lang['no_image_found']);

} ###### End of if statement.


;)

well... what does exactly do the -> show_error_page() <- function?
Title: Re: watermark when showing pic
Post by: TheOracle on September 14, 2005, 01:48:17 AM
Quote

well... what does exactly do the -> show_error_page() <- function?


It returns, in this case, the ' no permission ' page by keeping the site layout as it should. Otherwise, it will return a restricted message with a white page. ;)
Title: Re: watermark when showing pic
Post by: impss on September 14, 2005, 01:50:22 AM
If anyone is Interested this is the php file I use to add text to a image on the fly

Code: [Select]
<?php
//=========== change the text to display in the image
$text 'YOURTEXT';
$imgfile$_GET['get_image'];
$font 'arial.ttf';
$ext=substr($imgfile,-3);
$ext=strtolower($ext);

if(
$ext=="jpg" || $ext=="jpe"$im=@imagecreatefromjpeg("$imgfile");
elseif (
$ext=="gif"$im=@imagecreatefromgif("$imgfile"); 
else {print 
"Unknown image format"; exit;}

 if (!
$im) { /* See if it failed */
 
      $im ImageCreate (15030); /* Create a blank image */
 
      $bgc ImageColorAllocate ($im255255255);
 
      $tc  ImageColorAllocate ($im000);
 
      ImageFilledRectangle ($im0015030$bgc); 
 
      /* Output an errmsg */
 
      ImageString($im155"Error loading $imgfile"$tc); 
return $im;
 
  }

$x=imagesx($im);
$y=imagesy($im);
$fontsize=$x/40;
$fontsize=floor($fontsize);
if(
$fontsize<10$fontsize=10;

$white imagecolorallocate($im255255255);
$black imagecolorallocate($im000);

imagettftext($im$fontsize012$fontsize+8$black$font$text);
imagettftext($im$fontsize010$fontsize+6$white$font$text);

if(
$ext=="gif"
{
header("Content-type: image/gif");
imageGIF($im);
}
else
{
header("Content-type: image/jpeg");
imagejpeg($im);

}
imagedetroy($im);
?>
Title: Re: watermark when showing pic
Post by: TheOracle on September 14, 2005, 01:52:33 AM
Hum ... are these functions intended to be used as part of the execution of 4images ?
Title: Re: watermark when showing pic
Post by: okram on September 14, 2005, 01:56:01 AM
If anyone is Interested this is the php file I use to add text to a image on the fly

Code: [Select]
<?php
//=========== change the text to display in the image
$text 'YOURTEXT';
$imgfile$_GET['get_image'];
$font 'arial.ttf';
$ext=substr($imgfile,-3);
$ext=strtolower($ext);

if(
$ext=="jpg" || $ext=="jpe"$im=@imagecreatefromjpeg("$imgfile");
elseif (
$ext=="gif"$im=@imagecreatefromgif("$imgfile"); 
else {print 
"Unknown image format"; exit;}

 if (!
$im) { /* See if it failed */
 
      $im ImageCreate (15030); /* Create a blank image */
 
      $bgc ImageColorAllocate ($im255255255);
 
      $tc  ImageColorAllocate ($im000);
 
      ImageFilledRectangle ($im0015030$bgc); 
 
      /* Output an errmsg */
 
      ImageString($im155"Error loading $imgfile"$tc); 
return $im;
 
  }

$x=imagesx($im);
$y=imagesy($im);
$fontsize=$x/40;
$fontsize=floor($fontsize);
if(
$fontsize<10$fontsize=10;

$white imagecolorallocate($im255255255);
$black imagecolorallocate($im000);

imagettftext($im$fontsize012$fontsize+8$black$font$text);
imagettftext($im$fontsize010$fontsize+6$white$font$text);

if(
$ext=="gif"
{
header("Content-type: image/gif");
imageGIF($im);
}
else
{
header("Content-type: image/jpeg");
imagejpeg($im);

}
imagedetroy($im);
?>

I used that for sometime, but i decided not to use a text watermark but a image watermark... As far as i know the imagettftext() function requires a special library (freefonttype  :?: i do not remember the exact name) Once it didn't worked, so i started with an image watermark

Regards
Title: Re: watermark when showing pic
Post by: impss on September 14, 2005, 01:57:17 AM
Hum ... are these functions intended to be used as part of the execution of 4images ?

If your refering to me, I used this code in place of this mods watermark.php
Title: Re: watermark when showing pic
Post by: okram on September 14, 2005, 01:57:53 AM
Hum ... are these functions intended to be used as part of the execution of 4images ?

which functions do you mean?
Title: Re: watermark when showing pic
Post by: TheOracle on September 14, 2005, 01:58:56 AM
Quote

As far as i know the imagettftext() function requires a special library (freefonttype  Question i do not remember the exact name)


Correct. The name is GD Library which must be installed from the server end in order, for this MOD, to work properly. ;)
Title: Re: watermark when showing pic
Post by: TheOracle on September 14, 2005, 01:59:49 AM
Quote

which functions do you mean?


Sorry, I meant codings - not functions. My bad. Are these codings intended to work under 4images ?
Title: Re: watermark when showing pic
Post by: impss on September 14, 2005, 02:00:33 AM

I used that for sometime, but i decided not to use a text watermark but a image watermark... As far as i know the imagettftext() function requires a special library (freefonttype  :?: i do not remember the exact name) Once it didn't worked, so i started with an image watermark

Regards

Yea, I was just offering this as another option
Title: Re: watermark when showing pic
Post by: okram on September 14, 2005, 02:01:34 AM
Correct. The name is GD Library which must be installed from the server end in order, for this MOD, to work properly. ;)

No i didn't mean the gd library... that's for copying 1 image into another... for adding text to 1 image there's another library that muist be installed... let me find out more about this library and then i will make a new post here

Title: Re: watermark when showing pic
Post by: okram on September 14, 2005, 02:05:12 AM
Sorry, I meant codings - not functions. My bad. Are these codings intended to work under 4images ?

If you're refering to this watermark codes, yeah they are intended to work along with 4images... it's just a mod for it... i guess

Regards
Title: Re: watermark when showing pic
Post by: okram on September 14, 2005, 02:12:24 AM
let me find out more about this library and then i will make a new post here

This function requires both the GD library and the FreeType library....

yeah that's it... the name is freetype library...

Please read this article -> http://cheetahscripts.com/modules.php?name=PHP_Manual&page=function.imagettftext.html <- That's what i meant

Regards
Title: Re: watermark when showing pic
Post by: TheOracle on September 14, 2005, 02:14:44 AM
Thanks for mentionning about the freetype module.

As for :

Quote

it's just a mod for it... i guess


Well ... actually, I don't mean to be rude but, even if the idea is great, it is a highly unsecured one as no sessions protection has been preset in that MOD.  8O
Title: Re: watermark when showing pic
Post by: okram on September 14, 2005, 02:26:07 AM
Well ... actually, I don't mean to be rude but, even if the idea is great, it is a highly unsecured one as no sessions protection has been preset in that MOD.  8O

I think there's no a strong reason to prevent the direct access to this file. At least in my case, it's not in my plans setting a complete high secure system for this page... all we want is prevent the direct access from standard users... i mean we don't expect all visitors know php programming or stuff like that.. as i said... all we want is prevent the directaccess to standard users, and those users represent the 95 % or more of our visitors... so i think no secure systems are required for this last mod, the one that sets a session variable...

Regards
Title: Re: watermark when showing pic
Post by: TheOracle on September 14, 2005, 02:41:47 AM
Quote

ll we want is prevent the direct access from standard users


If it's the case, then I'd strongly advise you re-evaluate your codes again as no restrictions has been set-up in order to block anonymous visits on that MOD. ;)

Quote

so i think no secure systems are required for this last mod


It is up to you of course. Althought, I'd still recommend that you do so. ;)
Title: Re: watermark when showing pic
Post by: okram on September 14, 2005, 02:57:46 AM
no restrictions has been set-up in order to block anonymous visits on that MOD. ;)
Yes there have... in the watermark.php file we check the existance of the $_SESSION['_access_is_correct']-variable... if it hasn't been set... then we don not show the pic, but an error message... i chose the page_header.php file to set our variable, because this page is included in all the gallery php-files, just to mention: details.php, postcard.php, etc etc... BUT it is not included at all in the watermark file, so if the user type the url http://mysite.com/gallery/watermark.php?id=353 wont see any image as long as the variable does not exists... Standard users won't know of course how to create this variable manually... and in page_footer.php, which is also include in all pages, we unset the variable just in case it is set yet... i think it's enough with that

It is up to you of course. Althought, I'd still recommend that you do so. ;)
I stand by what i said before... i do not come to a reason for highly-prottecting this file...

The only thing i care in this mod is avoid users access to unmarked images...

Regards
Title: Re: watermark when showing pic
Post by: TheOracle on September 14, 2005, 03:05:50 AM
Quote

$_SESSION['_access_is_correct']


You should really replace that

with :

Code: [Select]

$user_info['user_level'] != GUEST


instead. ;)

Quote

i think it's enough with that


Sure. Have a good one. 8)
Title: Re: watermark when showing pic
Post by: okram on September 14, 2005, 06:13:29 AM
Quote
Quote

$_SESSION['_access_is_correct']



You should really replace that

with :


Code:

$user_info['user_level'] != GUEST


instead.


I've done a general overview of the last 20 posts in this topic, and I've come to the conclussion that there's a misunderstanding with the direct-access-prevent stuff... when we say we want to prevent the direct access to the watermark php-file we are not talking about the user level... i mean guests, registered users or admins... I think you TheOracle understood all this like that.

When saying direct-access we are talking about accessing the WMark file by writting the url in the browser...

Quote
no restrictions has been set-up in order to block anonymous visits on that MOD.

I guess you mean unregistered users when you say {anonymous visits}... In fact, we dont care if the user is registered or not, logged in or not... I think that can be well configured from the 4images control panel... As i said, all we want to do is avoid direct accessing by typing the watermark.php URL in the browser...

That's why i check a  session var instead of checking the user level...

Quote
$user_info['user_level'] != GUEST

The reason to prevent this direct access is just to avoid massive downloads of pics out of the details.php page, which is bound to show the images...

P.D. Sorry 4 my bad english  :lol: ... in fact i'm a spanish speaker  :?
Title: Re: watermark when showing pic
Post by: TheOracle on September 14, 2005, 11:48:40 AM
My earlier posts was simply about suggested / recommended technics since you wish to use it under 4images. ;)
Title: Re: watermark when showing pic
Post by: marius26 on December 20, 2005, 05:56:09 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.)

works like a charm, no problems , check on my site, click on pic at the bottom to see this script in action.
Title: Re: watermark when showing pic
Post by: Lukazs on December 25, 2006, 11:39:11 AM
Hi,

Is it possible to use only one of this script ability to not show full patch to image? I'm talking about watermark.php?image_id=xxx, this works great for images but how to set it to show other files? It's no needed to add watermark, just image_id=xx instead of data/media/489/game_shooting.swf in the end of site url.

Thanks.  :wink: :oops: 8O
Title: Re: watermark when showing pic
Post by: Benjamin on April 20, 2007, 06:32:38 PM
Hi all!

First of all I want to thank the topicstarter and the people who gave help! So...Thanks! Because the main meaning of the Mod is working for me, but there is a problem:

The things I did:

- put the 'watermark.php' in the 4images root
- put a 'watermark.png' image in the 4images root
- added the line (<img src="watermark.php?get_image={media_src}">) in jpg.html

Everything is working BUT the uploaded photo is now posted 2 times, under eachother :S It looks like this -> http://www.relic-hunters.nl/gallery/details.php?image_id=3

How do I get rid of that?

Friendly regards,
Benjamin

P.S. Sorry for my bad English!
Title: Re: watermark when showing pic
Post by: Benjamin on April 20, 2007, 06:47:01 PM
hi,
this mod is better
http://www.4homepages.de/forum/index.php?topic=13719.0

gruss ivan

Is it ? I can't even find Instalation Notes... Don't know how to install it if the docs aren't there... :oops:
Title: Re: watermark when showing pic
Post by: Benjamin on April 20, 2007, 07:46:08 PM
Thank you very much! Got the wrong instalation files...because the info wasn't there... Downloaded it from another place.

It's working now! Thank you! :D
Title: Re: watermark when showing pic
Post by: almighty7 on March 01, 2009, 10:54:40 PM
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);
  }
}

:?:

I tried to do this, but I don't find the lines in the download.php. That's because I have 4images 1.7.6.

I have a mod that makes an annotation over a watermark.php file (a transparent PNG). Unfortenately I want the Watermark to appear on the downloaded image, too, but I don't want to brand the pictures with the annotation (because I want to use the original ones for another thing).

Can anybody help me