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

0 Members and 1 Guest are viewing this topic.

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 #15 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?
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 #16 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

Offline triaphoto

  • Pre-Newbie
  • Posts: 7
    • View Profile
    • Ironman Triathlon Pictures - Fotos
Re: watermark when showing pic
« Reply #17 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.

 

 

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #18 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)

Offline triaphoto

  • Pre-Newbie
  • Posts: 7
    • View Profile
    • Ironman Triathlon Pictures - Fotos
Re: watermark when showing pic
« Reply #19 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
 

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #20 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

Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Re: watermark when showing pic
« Reply #21 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.
ch€ri{Bi}²


Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #22 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

Offline Xyu BAM

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: watermark when showing pic
« Reply #23 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.

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #24 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

Offline impss

  • Sr. Member
  • ****
  • Posts: 382
    • View Profile
    • Cusstom.net
Re: watermark when showing pic
« Reply #25 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

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #26 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

TheOracle

  • Guest
Re: watermark when showing pic
« Reply #27 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.


;)

Offline okram

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: watermark when showing pic
« Reply #28 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

Offline impss

  • Sr. Member
  • ****
  • Posts: 382
    • View Profile
    • Cusstom.net
Re: watermark when showing pic
« Reply #29 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