Jump to content

Page Image Manipulator | API for 1 & 2


horst

Recommended Posts

Thanks for the info and the module! I will try it out when I have a bit more time. So, you influence filesizes with specifying the quality level (0-100). You can set it sitewide in the config.php (default is 90) or you can pass it individually in an options array everywhere on API level.

Is the last file in your screenshot created via GD, and what setting for quality have you used?

Link to comment
Share on other sites

Both (with your module and with my module) used default quality option "90" and GD library used. Didn't test "Imagick" Library yet but it must work, if extension is installed.

I checked difference between "Imagick" and "GD" there not much difference about file sizes. Comments about "Imagick" quality is much better for compression than "GD".

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

A little tip that non-advanced users like me might appreciate:

foreach ($galleryimages as $image) {
  ini_set('max_execution_time', 1200);  // this line resets the timer for max_execution_time with every loop.
  $infoarray = $image->pim2Load('f-')->getImageInfo();
  $thumb = $image->pim2Load('t-')->width(200)->pimSave()->url;
  $full = $image->url;
  if ($infoarray['width'] > 2000) {
    $full = $image->pim2Load('f-')->width(2000)->pimSave()->url;
  }
  echo "<div class='galleryimage'><img class='jslghtbx-thmb' src='$thumb' data-jslghtbx='$full' data-jslghtbx-group='galtsu' data-jslghtbx-caption='$image->description'></img></div>";         
}

That code will skip resizing with PIM, if the original width is not over 2000px.

Link to comment
Share on other sites

  • 1 month later...

awesome module horst, thank you very much!

think i found a little bug?

// config.php
$config->imageManipulatorOptions = array(
    'outputFormat' => 'png'
);
// template
$image = $image->pim2Load('sticker')->grayscale()->pimSave();

does create a jpg.

$image = $image->pim2Load('sticker')->grayscale()->setOutputFormat('png')->pimSave();

does create a png (that's what i wanted, but setting it in config.php seems not to work)

Link to comment
Share on other sites

It is not intended to be set as global / default option sitewide. You definitly need to set it with every request. The default behave is, if you do not explicitly define an outputformat, the outputformat is the same as the inputformat:

  • jpg => jpg
  • jpg => setOutputformat('png') => png

So, it is not a bug in the module, but a "bug" in the description here. :)

I will update the description. Thanks for pointing out, @BernhardB.

  • Like 2
Link to comment
Share on other sites

don't know how hard that would be to implement but in my case it would be better if it was configurable globally. maybe if it is NOT set it will stay "auto" like it is now, but if it is set to eg "png" it will use this as default?

definitely no big issue - just a suggestion for a very very very small improvement ;)

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

@horst

would it be possible to achieve a stronger blur (like this image on the right: http://codepen.io/tobaco/pen/ZWBRwX)%C2'> effect then the currently available (blur or smooth) with PIM and GD?

i tried various things (playing with transparency and overlaying or multiple blur calls).

the first attempt looks really cheap and the second is to ressource hungry to work for the desired blur effect.

i know that imageMagick can do this, but unfortunately that's no option here. :-/

thanks!

Link to comment
Share on other sites

@Horst

Thank you for this module. I've hit the anti-aliasing problem in watermarkText() you mentioned back on page 2 of this thread (I'm using PHP7). This fixed the issue for me...

if (function_exists('imageantialias')) { @imageantialias($im1, FALSE); }
  • Like 3
Link to comment
Share on other sites

Thank you for this module. I've hit the anti-aliasing problem in watermarkText() you mentioned back on page 2 of this thread (I'm using PHP7). This fixed the issue for me...

if (function_exists('imageantialias')) { @imageantialias($im1, FALSE); }

Thank you for the good news! (and the fix) ^-^

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hi,
I don't know if depends of PW devns 3.0.10 or something in my code but this

$watermark = $config->paths->root.$config->site_cdn."wm.png";  
$options = array('outputFormat'=>'jpg','quality'=>70);
// first method
$pic->image->first()->pim2Load('wtm')->setOptions($options)->watermarkLogo($watermark,'SE',8)->pimSave();
// another try
$pixelateVersion = $pic->image->first()->pim2Load('pxtd',true)->setOptions($options)->width(700)->pixelate(30)->pimSave();
$pic->image->add($pixelateVersion);
simply overwrites the first image file without creating a copy with prefix as expected.
I copied this code from another pw installation (2.6)
Link to comment
Share on other sites

I'm using pim2 as you can see from the code "->pim2Load".

Oh, sorry!

--- --- ---

Is $pic->image an imagefield set to hold multiple images or only one image?

Please, can you, for debug purposes, output the filename of the variation, instead of adding it to the imagefield?

$options = array('outputFormat'=>'jpg','quality'=>70);
$originalImage = $pic->image->first();
$pixelateVersion = $originalImage->pim2Load('pxtd',true)->setOptions($options)->width(700)->pixelate(30)->pimSave();
echo "<p>{$originalImage->filename}<br />{$pixelateVersion->filename}</p>";
Edited by horst
Link to comment
Share on other sites

Hhm, for me it is working:

D:/ProcessWire/PW-DEV/pw30/htdocs/site/assets/files/1/nikon2208.jpg
D:/ProcessWire/PW-DEV/pw30/htdocs/site/assets/files/1/nikon2208.-pim2-pxtd.jpg

I used PW 3.0.10

You may look at other modules that work with files and images. Maybe you can create a siteprofile with the exporter or are you able to temporarily disable site-modules in the original site?

So, your code is working, the Pim2 is working, but not in your setup. If possible, I would disable all (autoload and file/image-related) modules, and try if it works then. If yes, enable one module after the other, and check if it is working or if it breaks again.

Or the other way round: disable one module, check if it changes, if not disable the next one, ..., ...

YOu may also first have a look to the Hooks-Section of the Debug Mode Tools in the admin footer to get an overview which modules hook into what, maybe this way you can spot primarily candidates very fast. It all depends on your setup I believe.

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Hello, where can I get the PIM2 Module ? currently used with pw. 3.0.23 from the ModulesManager cant find the pim2 Link the one on the first side doesnt work for me. 

And is it on the Memory only ? If i check the variations the is see something like this. 

http://prntscr.com/bmm8aa 

The first two images are generated with the PW Api. 

If its only in the memory it couldnt be used with many of images on one site ? 
 

Tnx  

Link to comment
Share on other sites

simply go to the modules directory, you find it directly on the first page under "User Favorites", the second item.

Or here.

Your other questions I don't understand. ??

In the modules package are a module pim1 and a module pim2. If you use a PW version greater than 2.5.11, please do not install pim1, install pim2! That's all. Hope this helps?

Link to comment
Share on other sites

Yes, please only use the second one. Best is to uninstall the first one. The first one is obsolete, as it only supports the older image variations naming convention, and not the new one, introduced in PW 2.5.11.

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Uhm, - doesn't sound good. Transparency has made problems all the last twenty years with GD. I'm not sure, but maybe I have read something about that they have updated their Lib to support it. Maybe the version what is bundled with PHP-7 does support it now (?) <- Not sure on this.

Other than that, I believe we can do nothing. (Using any function would result into the same) :(

 

Link to comment
Share on other sites

@POWERFULHORSE, if you have Imagick installed on your server you can try a slightly modified version (below) of the function I introduced in this post.

// ImageMagick effects
function imagickal($imagePath, $format, $method, array $arguments) {
    $path_parts = pathinfo($imagePath);
    $dirname = $path_parts['dirname'] . '/';
    $filename = $path_parts['filename'];
    $mod = $method . '-' . implode($arguments, '-');
    $mod = wire('sanitizer')->filename($mod, true);
    $savename = "{$dirname}{$filename}_{$mod}.{$format}";
    if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $savename)) {
        $image = new Imagick($_SERVER['DOCUMENT_ROOT'] . $imagePath);
        call_user_func_array([$image, $method], $arguments);
        $image->setImageFormat($format);
        $image->writeImage($_SERVER['DOCUMENT_ROOT'] . $savename);
    }
    return $savename;
}

I tested it as follows...

$orig = "/site/templates/images/transparent.png";
$after = imagickal($orig, 'png', 'negateImage', [false]);
echo "<img src='$orig'>";
echo "<img src='$after'>";

...and the results...

transparent.pngtransparent_negateImage.png

  • Like 6
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
×
×
  • Create New...