Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4255
Latest: andreios
New This Month: 3
New This Week: 1
New Today: 0
Stats
Total Posts: 43259
Total Topics: 7518
Most Online Today: 201
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 184
Total: 184

Author Topic: Questions about Watermarking  (Read 2517 times)

0 Members and 1 Guest are viewing this topic.

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Questions about Watermarking
« on: February 08, 2017, 01:29:31 pm »
I would like to enable watermarking on my gallery items moving forward. I have a few thoughts and concerns:

1) Is there a way to make the watermark letters have a glow? For example, if I choose the color white, for instance, the letters should have a shadow in case it is imposed on a white picture.

2) Does the watermark function have the ability to size the font in accordance to the dimensions of the picture? For example, if the picture is 200 by 200, the text will fit that dimension.

3) Can the text go across the picture from bottom-left corner to top-right corner?

4) Is it possible to hack the function so that the original picture is left untouched while only the medium-sized version contains the watermark.

Thank you

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Questions about Watermarking
« Reply #1 on: February 08, 2017, 01:49:06 pm »
It's hit or miss. I currently do not like how I have it setup at the moment.
I would test it out trial images and see how it works. it does not keep original images
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Questions about Watermarking
« Reply #2 on: February 08, 2017, 03:00:03 pm »
I did some testing and found out that the watermark image does not get resized based on the parent, although I will add this new code found here

http://stackoverflow.com/questions/11693644/scaling-a-watermark-to-fit-parent-image

Code: [Select]
$image = imagecreatefromjpeg('http://mydomain.com/myPhoto.jpg');
$imageSize = getimagesize('http://mydomain.com/myPhoto.jpg');

$watermark = imagecreatefrompng('http://mydomain.com/myWatermark.png');

$watermark_o_width = imagesx($watermark);
$watermark_o_height = imagesy($watermark);

$newWatermarkWidth = $imageSize[0]-20;
$newWatermarkHeight = $watermark_o_height * $newWatermarkWidth / $watermark_o_width;

imagecopyresized($image, $watermark, $imageSize[0]/2 - $newWatermarkWidth/2, $imageSize[1]/2 - $newWatermarkHeight/2, 0, 0, $newWatermarkWidth, $newWatermarkHeight, imagesx($watermark), imagesy($watermark));

imagejpeg($image);

imagedestroy($image);
imagedestroy($watermark);

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Questions about Watermarking
« Reply #3 on: February 08, 2017, 08:39:31 pm »
Interesting will take a look.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Questions about Watermarking
« Reply #4 on: February 21, 2017, 01:10:58 am »
I'm finalizing the changes in the watermark function. Need crucial help in this next step:

I modified DoWaterMark to this:

Code: [Select]
function DoWaterMark($filename)
{
global $modSettings, $sourcedir, $gd2;

if (empty($modSettings['gallery_set_water_enabled']))
return;

// Picture watermark
if ($modSettings['gallery_set_water_image'] != '')
{
// If the image exists
if (file_exists($modSettings['gallery_set_water_image']))
{
$photo = new imagick_watermark($filename);
$photo->watermark($modSettings['gallery_set_water_image'],'CC', .6, 2, false);
}
}
}

Note: I removed the text application.

I then used this class, placed it into gallery.php

Code: [Select]
class imagick_watermark extends Imagick {
   
    public function watermark( $wm, $ps = 'BR', $alpha = .8, $scale = 10, $dwm = TRUE)
{   
        // Image Watermark Valid Positions
        $iwvps = 'BL BC BR TL TC TR CC';
       
        // if a string is passed for the watermark
        // check if it is a file and readable
        // try and load the Imagick object with this file
        if(is_string($wm)) {
            if(is_file($wm)) {
                if(is_readable($wm)) {
                    $wm = new Imagick($wm);
                }
            }
        }
       
        // Double check watermark image is an object
        if(!is_object($wm)) {
            trigger_error('Object type Imagick epected.', E_USER_ERROR);
            return;
        }
       
        // And is an Imagick object
        if(get_class($wm) != 'Imagick') {
            trigger_error('Object type Imagick epected.', E_USER_ERROR);
            return;
        }
           
        // Check alpha settings
        // We want a number between 0 and 1
        if($alpha < 0 || $alpha > 1) {
            trigger_error('Alpha setting out of range - '.$alpha, E_USER_ERROR);
            return;
        }
       
        // check position settings
        // if string passed
        if(is_string($ps)) {
            $ps = strtoupper($ps);
            if(!strstr($iwvps,$ps)) {
                trigger_error('Position Setting `'.$ps.'` invalid. ('.$iwvps.')', E_USER_ERROR);
                return;
            }
        // if an array was passed
        // for exact position
        } elseif(is_array($ps)) {
            if(!isset($ps['x']) || !isset($ps['y'])) {
                trigger_error('Position Setting invalid. Exact placement failed. Use $ps[\'x\'] & $ps[\'y\']', E_USER_ERROR);
                return;
            }
        } else {
            trigger_error('Position Setting Faild.', E_USER_ERROR);
            return;
        }
       
        // check dwm destroy watermark on finish
        if(!is_bool($dwm)) {
            trigger_error('Switch for destroying Watermark Image must be of type bool.', E_USER_ERROR);
            return;
        }
        // how big are the images?
        // this image
        $iWidth = $this->getImageWidth();
        $iHeight = $this->getImageHeight();
       
        // the watermark image
        $wWidth = $wm->getImageWidth();
        $wHeight = $wm->getImageHeight();
           
        // resize the watermark
        $wm->scaleImage($iWidth/$scale, 0);

        // get new size of the watermark image
        $wWidth = $wm->getImageWidth();
        $wHeight = $wm->getImageHeight();
       
        // Set the transparency of the watermark image
        // Defaults to .8 0 Complete Transparency - 1 No Transparency
        $wm->evaluateImage(Imagick::EVALUATE_MULTIPLY, $alpha, Imagick::CHANNEL_ALPHA);
       
        // calculate the position
        // if were using predefined positions
        if(is_string($ps)) {
            switch ($ps) {
               
                // Bottom Right
                case 'BR' :
                    $x = ($iWidth - $wWidth);
                    $y = ($iHeight - $wHeight);
                    break;
               
                // Bottom Left
                case 'BL' :
                    $x = 0;
                    $y = ($iHeight - $wHeight);
                    break;
               
                // Top Left
                case 'TL' :
                    $x = 0;
                    $y = 0;
                    break;
               
                // Top Right
                case 'TR' :
                    $x = ($iWidth - $wWidth);
                    $y = 0;
                    break;
               
                // Center Top
                case 'TC' :
                    $x = (($iWidth/2) - ($wWidth/2));
                    $y = 0;
                    break;
                   
                // Center Bottom
                case 'BC' :
                    $x = (($iWidth/2) - ($wWidth/2));
                    $y = ($iHeight - $wHeight);
                    break;
                   
                // Center Center
                default :
                    $x = (($iWidth/2) - ($wWidth/2));
                    $y = (($iHeight/2) - ($wHeight/2));
                    break;
            }
        } else {
            // if we are using exact cordinates
            $x = $ps['x'];
            $y = $ps['y'];
        }
       
        // Add the water mark to this image
        $this->compositeImage($wm, imagick::COMPOSITE_OVER, $x, $y);
       
        // destroy the watermark image
        if($dwm === TRUE) {
            $wm->destroy();
        }
    }
}

Problem, however is that I don't know how to merge them. If I were to hypothetical:

Code: [Select]
$photo = new imagick_watermark('/pathway/gallery/medium_6_21_02_17_1_27_56.png');
 $photo->watermark('/pathway/gallery/6_21_02_17_12_52_53.png','cc', .6, 2, false);
 
 header("Content-Type: image/png");
 echo $photo;

It would display the image, so what am I missing here?

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Questions about Watermarking
« Reply #5 on: February 21, 2017, 01:38:38 am »
Got it:

Set: $photo->writeImage($filename);

 

Related Topics

  Subject / Started by Replies Last post
4 Replies
7088 Views
Last post February 21, 2007, 06:44:49 am
by clarkkent93
1 Replies
3568 Views
Last post July 07, 2007, 05:53:52 am
by SMFHacks
3 Replies
5964 Views
Last post July 25, 2007, 11:04:10 pm
by SMFHacks
1 Replies
4446 Views
Last post August 10, 2008, 09:44:06 am
by SMFHacks
3 Replies
3119 Views
Last post July 10, 2011, 09:48:48 am
by SMFHacks

+- Recent Topics

No thumbnails on new uploads by SMFHacks
March 27, 2024, 02:10:41 pm

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

an idea for new mod (( content type with different display )) by SMFHacks
February 27, 2024, 01:36:27 pm

[Mod] RSS Feed Poster by SMFHacks
February 27, 2024, 11:57:18 am

find duplicate pictures by fvlog19
February 14, 2024, 02:22:40 pm

Error uploading video. by SMFHacks
February 08, 2024, 02:04:16 pm

Gallery icon as last added image by fvlog19
February 01, 2024, 01:04:56 pm

Powered by EzPortal