Jump to content

[SOLVED] How do i add watermakr to image? cant seem to make it work with PW


picarica
 Share

Recommended Posts

so hello i am trying to combine my whole ass gallery with custom created watermark, i wanted to combine my images with simple text little opaque but that seemed harder and i couldnt make it work, well i cant make this work either, how are you handling watermarks? i would prefer if it would be plain PHP no imagemagick or some custom plugins scripts, but if neccesary i wont deny.

so here's my code

    $pa = $pages->find("template=basic-page|art_gallery, images.tags!=''");
    /* $pa = $pages->find("has_parent!=2,id!=2|7,status<".Page::statusTrash.",include=all"); */
    echo "<div BRUUH class='row gtr-50 gtr-uniform js-filter' id='gal'  >";
    foreach ($pa as $p) {
        foreach($p->images as $image) {
            $obrazok = $image->url;
            $image = imagecreatefromjpeg($obrazok);
            $frame = imagecreatefromjpeg($pages->get('/settings/')->watermark->url);
           /* echo $image;
           echo $frame; */
 
            # If you know your originals are of type PNG.
            
            imagecopymerge($image, $frame, 0, 0, 0, 0, 50, 50, 100);
            
            # Output straight to the browser.
            $img = imagepng($image);
 
 
            $options = array('quality' => 70, 'upscaling' => true, 'cropping' => 'center', 'sharpening'=>'medium');
            $thumb = $img->size(400, 300, $options);
            $large = $img->size(1200, 0, $options);
            echo "<div class='$image->tags' class='col-4'>";
            echo "<span style='overflow:hidden;'class='image fit'>";
            echo "<a href='$large->url'>";
            echo "<img class='uk-transform-origin-top-right' uk-scrollspy='cls: uk-animation-fade; repeat: false' src='$thumb->url'  alt='$image->tags'>";
            echo "</a>";
            echo "</span>";
            echo "</div>";
        }
    };

 

Edited by picarica
made is solved
Link to comment
Share on other sites

Not plain PHP, but there are a couple of ProcessWire modules that can help you here:

  • Page Image Manipulator 2 has multiple methods for watermarking images.
  • AvbImage provides a method called insert(), which (to my best understanding, haven't used it myself) applies another image on top of the first one (so, basically, creates a watermark).
  • Like 1
Link to comment
Share on other sites

If you have a whole ass gallery (not sure, but I think that is a lot ?) you may want to consider batch processing your images outside of Processwire. I have a few *nix shell scripts that watermark my whole ass gallery. Not poking fun, that is just really funny. Let me know if you would like to take a look at them.

Link to comment
Share on other sites

With the module PageimageManipulator you can find a description for "watermarkLogo" that will result in a code like this in your template file:

$frame = $pages->get('/settings/')->watermark;
foreach($images as $image) {
    $wmImage = $image->pim2Load('wm', ['quality'=>100, 'sharpening'=>'none', 'defaultGamma'=>-1])->watermarkLogo($frame, $position='NW', $padding=1.5)->pimSave();

	// do something with $wmImage

}

You can find the API explained here (look out for watermarkLogo): 

 

And there is a post about simple text here: https://processwire.com/talk/topic/4264-page-image-manipulator-1/?tab=comments#comment-41989

 

But if you want to use simple text on the images, it would be better not to use my module. Instead try Ukyos avbImage! There is more and better support for simple text watermarks:

 

  • Like 3
Link to comment
Share on other sites

6 hours ago, teppo said:

Not plain PHP, but there are a couple of ProcessWire modules that can help you here:

  • Page Image Manipulator 2 has multiple methods for watermarking images.
  • AvbImage provides a method called insert(), which (to my best understanding, haven't used it myself) applies another image on top of the first one (so, basically, creates a watermark).

avbimage seems fine but i have problems implementing it into my code beacuse
 

                $insert = $page->images()->first()->image()->insert($pages->get('/settings/')->watermark, 'bottom-right', 10, 10);
                echo "<img src='{$insert->encode('data-url')}' />";

cannot work so i edited it with

$insert = $image->images()->first()->image()->insert($pages->get('/settings/')->watermark, 'bottom-right', 10, 10);

yet i still get error

Breaking news… Error: Exception: Method Pageimage::images does not exist or is not callable in this context (in wire/core/Wire.php line 544)

not sure what i am doing wrong, i dont get it why there is images function the first function then AGAIN image function? is that all neccessary when i have it in foreach

so in my logic it should be like

$insert = $image->image()->insert($pages->get('/settings/')->watermark, 'bottom-right', 10, 10);

yet still error
 

Arrgh… Error: Exception: Image source not readable (in site-artgallerytaube_eu/modules/AvbImage/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php line 302)

not sure what to do with it.

 

5 hours ago, rick said:

If you have a whole ass gallery (not sure, but I think that is a lot ?) you may want to consider batch processing your images outside of Processwire. I have a few *nix shell scripts that watermark my whole ass gallery. Not poking fun, that is just really funny. Let me know if you would like to take a look at them.

thanks but no thanks i need to processwire handle it, there will be over 1000 images and continuing to grow every day, and i want to make it work now and not bother with it never again. but yeah with unix scripts is easy as pie with imagemagick but i want it plainly php or somewhint to do with PW

 

4 hours ago, horst said:

With the module PageimageManipulator you can find a description for "watermarkLogo" that will result in a code like this in your template file:


$frame = $pages->get('/settings/')->watermark;
foreach($images as $image) {
    $wmImage = $image->pim2Load('wm', ['quality'=>100, 'sharpening'=>'none', 'defaultGamma'=>-1])->watermarkLogo($frame, $position='NW', $padding=1.5)->pimSave();

	// do something with $wmImage

}

You can find the API explained here (look out for watermarkLogo): 

 

And there is a post about simple text here: https://processwire.com/talk/topic/4264-page-image-manipulator-1/?tab=comments#comment-41989

 

But if you want to use simple text on the images, it would be better not to use my module. Instead try Ukyos avbImage! There is more and better support for simple text watermarks:

 

i really like your plugin actually wanted to try it out but only found docs for pim1 and not pim2, arent there many syntax differences? i might try it out just because avbImage is doing me naughty

Link to comment
Share on other sites

4 hours ago, horst said:

With the module PageimageManipulator you can find a description for "watermarkLogo" that will result in a code like this in your template file:


$frame = $pages->get('/settings/')->watermark;
foreach($images as $image) {
    $wmImage = $image->pim2Load('wm', ['quality'=>100, 'sharpening'=>'none', 'defaultGamma'=>-1])->watermarkLogo($frame, $position='NW', $padding=1.5)->pimSave();

	// do something with $wmImage

}

You can find the API explained here (look out for watermarkLogo): 

 

And there is a post about simple text here: https://processwire.com/talk/topic/4264-page-image-manipulator-1/?tab=comments#comment-41989

 

But if you want to use simple text on the images, it would be better not to use my module. Instead try Ukyos avbImage! There is more and better support for simple text watermarks:

 

just tried yout plugin works perfectly, i used it with premade tranparent iamge but one thing doesnt work the $position='NW', i tried changing it to 'center' or 'NE' but no changes, is it working properly? it seems like its defaulting ot the top left corner

Link to comment
Share on other sites

12 hours ago, picarica said:

i tried changing it to 'center' or 'NE' but no changes, is it working properly? it seems like its defaulting ot the top left corner

It is working as expected since the positioning first was implemented. Here is the announcement post:

There is also a tip and a photoshop action for download available in the second post of the thread.

Do you use lowercase? https://github.com/horst-n/PageImageManipulator/blob/master/ImageManipulator02.class.php#L151-L162

If not please try with lowercase and report back. 

------

12 hours ago, picarica said:

but only found docs for pim1 and not pim2, arent there many syntax differences?

No there are no API differences, only the opening method is different: $image->pimLoad() becomes $image->pim2Load(). Thats all.
I changed the title of the first post for more clarity.

Link to comment
Share on other sites

1 hour ago, horst said:

It is working as expected since the positioning first was implemented. Here is the announcement post:

There is also a tip and a photoshop action for download available in the second post of the thread.

Do you use lowercase? https://github.com/horst-n/PageImageManipulator/blob/master/ImageManipulator02.class.php#L151-L162

If not please try with lowercase and report back. 

------

No there are no API differences, only the opening method is different: $image->pimLoad() becomes $image->pim2Load(). Thats all.
I changed the title of the first post for more clarity.

yes i tried anything, also there is not center in the github link u sent me, not sure what's wrong

this is the syntax                

$wmImage = $image->pim2Load('wm', ['quality'=>70, 'sharpening'=>'none', 'defaultGamma'=>-1])->watermarkLogo($frame, $position='w', $padding=1.5)->brightness(50)->pimSave();

maybe the image is weird? but is 1000×100 image. by the image i mean the watermark i used, its just text mildly edited ill post the resulting picture

Screenshot_20201024_144113.thumb.png.4ead5655a44384965631763dc596af41.png

just tried $position='center' and $position='C', it doesnt seem like updating ? but why no errors or logs

Link to comment
Share on other sites

45 minutes ago, picarica said:

just tried $position='center' and $position='C', it doesnt seem like updating ? but why no errors or logs

It seems to me (based on a very quick glance at the code) that both 'center' and 'c' are acceptable. Could you try setting it to 'center', then removing the generated image variation, and then loading the page again? My initial guess would be that the image is not changing since you're getting the previously created image back.

Alternatively you can provide a different prefix value for pim2Load; something like pim2Load('wm2', [...]).

Link to comment
Share on other sites

1 minute ago, teppo said:

It seems to me (based on a very quick glance at the code) that both 'center' and 'c' are acceptable. Could you try setting it to 'center', then removing the generated image variation, and then loading the page again? My initial guess would be that the image is not changing since you're getting the previously created image back.

Alternatively you can provide a different prefix value for pim2Load; something like pim2Load('wm2', [...]).

yep just as i thought after changing different prefix it loaded correctly, i wonder are old images stored in assets folder? if so i dont have permission to delete them, is there some option to flush old unused pics ?

Link to comment
Share on other sites

9 minutes ago, picarica said:

is there some option to flush old unused pics ?

See the API post: 

$image->pim2Load('wm')->removePimVariations() should do it, though you'd want to make sure that you don't leave this code in place longer than you need it (probably won't do a lot of harm, but it'd be pointless). I'm not sure if pim stores the images as regular variations, but if it does, you can also remove them by hand from the admin (edit the image and you should see variations somewhere in the GUI).

I wouldn't worry too much about those old variations, though. Most likely you haven't generated so many of them that they'd take considerable space on the disk, and anyone opening them accidentally is also quite unlikely.

  • Like 1
Link to comment
Share on other sites

8 hours ago, teppo said:

I'm not sure if pim stores the images as regular variations, but if it does,

yep, it stores them as regular pageimage variations and you can remove them by hand when opening "variations" in an image inputfield. You also can remove them by calling the core method $image->removeVariations(), but this also removes other variations like the adminThumbnail and maybe variations from CKE-fields and others. Therefore there is the pim2Load('ALIAS')->removePimVariations(), so that you can remove only the pimvariations for that specific alias name.

If you are in experimental mode with pim2, you have the option to load it with a second param (called $forceRecreation in the API page) that automatically refreshes this single variation. If you use a specific options array as second param with pim2Load(), you can set $forceRecreation as third param. ?

$image->pim2Load('wm', true)-> ...

 

  • Like 1
Link to comment
Share on other sites

On 10/24/2020 at 3:39 PM, teppo said:

See the API post: 

$image->pim2Load('wm')->removePimVariations() should do it, though you'd want to make sure that you don't leave this code in place longer than you need it (probably won't do a lot of harm, but it'd be pointless). I'm not sure if pim stores the images as regular variations, but if it does, you can also remove them by hand from the admin (edit the image and you should see variations somewhere in the GUI).

I wouldn't worry too much about those old variations, though. Most likely you haven't generated so many of them that they'd take considerable space on the disk, and anyone opening them accidentally is also quite unlikely.

yes thanks that function works perfectly, i just run it once, and generate new variations its good,  and ye i generated many i have over 200 MB of images rn

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...