Jump to content
horst

Page Image Manipulator 1

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@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!

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

I'm using pim2 as you can see from the code "->pim2Load". In any case (prefix or suffix) the original image has been replaced.
Anything to look in PW, some config options can interferes with the module?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

the image field holds multiple images, that was my first thought :)
the echo outputs the same filename, there is no variation, that's the problem, it replaces the original image 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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  

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Thaks for your answer I already installed the module from modules manager. Now I also installed the second version. Should i leave the first od better remove ? 

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Is it possible to invert a PNG with transparency with PIM? I have an image which is essentially a white (255,255,255) shape over a transparent background, and I would like to make the white shape black whilst maintaining the transparent area.

Share this post


Link to post
Share on other sites

I don't know. Have you tried it with negate ? What is the result?

Share this post


Link to post
Share on other sites

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) :(

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
    • By ukyo
      FieldtypeFontIconPicker
      Supported Icon Libraries
      FontAwesome 4.7.0 Uikit 3.0.34 IonicIcons 2.0.1 Cahangelog
      NOTE: Module store data without prefix, you need to add "prefix" when you want to show your icon on front-end, because some of front-end frameworks using font-awesome with different "prefix".
      Module will search site/modules/**/configs/IconPicker.*.php and site/templates/IconPicker.*.php paths for FieldtypeFontIconPicker config files.
      All config files need to return a PHP ARRAY like examples.
      Example config file : create your own icon set.
      File location is site/configs/IconPicker.example.php
      <?php namespace ProcessWire; /** * IconPicker : Custom Icons */ return [ "name" => "my-custom-icons", "title" => "My Custom Icon Set", "version" => "1.0.0", "styles" => array( wire("config")->urls->templates . "dist/css/my-custom-icons.css" ), "scripts" => array( wire("config")->urls->templates . "dist/js/my-custom-icons.js" ), "categorized" => true, "attributes" => array(), "icons" => array( "brand-icons" => array( "title" => "Brand Icons", "icons" => array( "google", "facebook", "twitter", "instagram" ) ), "flag-icons" => array( "title" => "Flag Icons", "icons" => array( "tr", "gb", "us", "it", "de", "nl", "fr" ) ) ) ]; Example config file : use existing and extend it.
      File location is site/configs/IconPicker.altivebir.php
      <?php namespace ProcessWire; /** * IconPicker : Existing & Extend */ $resource = include wire("config")->paths->siteModules . "FieldtypeFontIconPicker/configs/IconPicker.uikit.php"; $url = wire("config")->urls->templates . "dist"; $resource["scripts"] = array_merge($resource["scripts"], ["{$url}/js/Altivebir.Icon.min.js"]); $resource["icons"]["flag-icons"] = [ "title" => "Flag Icons", "icons" => array("tr", "en", "fr", "us", "it", "de") ]; $resource["icons"]["brand-icons"]["icons"] = array_merge($resource["icons"]["brand-icons"]["icons"], array( "altivebir" )); return $resource; After you add your custom config file, you will see your config file on library select box. Library Title (Location Folder Name).

      If your library categorized and if you have categorized icons set like uikit and fontawesome libraries, you will have category limitation options per icon field or leave it empty for allow all categories (default).

      Example : output
      if ($icon = $page->get("iconField")) { echo "<i class='prefix-{$icon}' />"; } MarkupFontIconPicker Usage
      // MarkupFontIconPicker::render(YourIconField=string, Options=array) echo MarkupFontIconPicker::render($page->YourIconField, [ 'prefix' => 'uk-icon-', // Icon class prefix, if you have different prefix, default is : "fa fa-" 'tag' => 'span', // Icon tag default is : "i" 'class' => 'fa-lg', // If you have extra cutom classes, for example : icons sizes, Array or Sting value 'style' => 'your custom styles if you have' // Array or String Value ]); Theme support

      Search support

      Category support

       
×
×
  • Create New...