horst

Module
Pia - Pageimage Assistant

45 posts in this topic

Pia - Pageimage Assistant

Hello, today I can tell you that Pia Ballerina want to assist you with Pageimages   pia-ballerina_titel.jpg
and that can become really helpful! :)
.
.
.
Pia, in its current state, version 1.0.0, provides:

  • a GUI (the module config screen) for quick and easy changes to the sitewide Pageimage default options
     
  • an alternative way for calling the Pageimage resizing methods with PW selector strings
     
  • three new methods as shortcuts to the resizing functions
     
  • a new method called retinafy and its alias hiDPI, (introduced in version 0.2.0)

.
.
.
2) Instead of ->width(), ->height(), ->size() you can call ->pia() now. With a PW selector string you tell Pia what image variation you want to have :
.

$image->pia("width=100, quality=80, sharpening=medium")->url;

.
If you want process ->width() just define width.
If you want process ->height() only define height.
If you want process ->size() just define width and height.
If you want process ->size() with equal values for width and height, just define only size, or use the alias square:
.

$image->pia("width=480")->url;
$image->pia("height=320")->url;
$image->pia("width=400, height=300")->url;
$image->pia("size=350")->url;
$image->pia("square=350")->url;

.
So, yes, - I see. Now you may think: "Ok, nice looking girl, - and she can dance very well, - but for what should it be good that she is involved here? My very old buddies width, height and size - and me, - we don't need any Ballerinas between us!"
.
Yeah, I see what you mean. But this above is not what Pia is good for, this is just a little warming up for you. :)
.
In some cases one need to specify more than just width and / or height. If it comes to that you need explicitly populated options with the individual pageimages, Pia will become faster and more comfortable at some point. Also the code is looking more readable with Pia, at least to me:
.

// regular style #1:

$image->width(800, array("upscaling" => false, "cropping" => true, "quality" => 80, "sharpening" => "strong"));

// or regular style #2:

$options = array("upscaling" => false, "cropping" => true, "quality" => 80, "sharpening" => "strong");
$image->width(800, $options);

// now lets Pia dance:

$image->pia('width=800, upscaling=0, cropping=1, quality=80, sharpening=strong');

$image->pia('width=800, upscaling=off, cropping=on, quality=80, sharpening=strong');

.
For me it is that not only Pia begin to dance, my fingers do so too when writing selector strings instead of the regular array code. :)
.  
Ok, last thing before we can go to stage: "You already may have noticed that Pia accepts few different values for boolean expression, yes?"

  • for TRUE you can write these strings: "1, on, ON, true, TRUE, -1"
  • for FALSE you may use one out of "0, off, OFF, false, FALSE"

Ready? Ok, lets go to stage.
.
.
.
3) Pia provide three new methods as shortcuts. This means that when using one of the shortcuts you have pre-populated options, regardless of the sitewide default settings:

  • crop :: does what the name says
     
  • contain :: is equal to the regular method: ->size($width, $height, array("cropping" => false))
     
  • cover :: this, Pias third child, is a new kid on the block :)

.
Let's have a closer look and compare it. We use Pias image from above as source for this example. (It's dimensions are 289 x 400 px)
.
.
* crop

$image->crop('square=100'); 

.
pia-ballerina_titel.100x100-piacrop.jpg    it is 100 x 100 px    and the name is:  pia-ballerina_titel.100x100-piacrop.jpg
.
.
.
* contain

$image->contain('square=100');

.
pia-ballerina_titel.100x100-piacontain.j    it is 73 x 100 px   and the name is:  pia-ballerina_titel.100x100-piacontain.jpg
.
.
.
* cover

$image->cover('square=100'); 

.
pia-ballerina_titel.100x139-piacover.jpg    it is 100 x 139 px   and the name is:  pia-ballerina_titel.100x139-piacover.jpg
.
.
.
Ok, you got it?
.
"Crop" crop out the area, "Contain" fits the image into the area, and "Cover" calculates the needed dimensions for the image so that the area is completly covered by it.
.
Following is a link with lots of those crop-, contain-, cover- variations. I have stress-tested it a bit: much variations
.
----------
.
.
Later Additions:
.
* contain with option weighten
Since version 0.0.6 contain can take an additional param called "weighten". (read more here)
.
.
.

* retinafy
Since version 0.2.0 retinafy is added. It returns a markup string, e.g. a HTML img tag, where placeholders are populated with property values from the pageimage. Default properties are: URL, WIDTH, HEIGHT, DESCRIPTION. The method also can take an optional array with CustomPropertyNames. You also can use the alias HiDPI if you like. (read more here)

.
.
----------
.
.
You can get the module from the modules directory or from the repo on Github:
.

git clone https://github.com/horst-n/PageimageAssistant.git your/path/site/modules/PageimageAssistant

.
.
Bye! 
.

 

pia-ballerina_outro.jpg

Classical ballet performance at the Aalto Theatre in Essen, in the context of the Red Dot Award ceremony 26 June 2007,
Act III, Sleeping Beauty, the wedding reception
Photos: Horst Nogajski - www.nogajski.de

 

34 people like this

Share this post


Link to post
Share on other sites

It is incredible how it is in this PW forum, You go to sleep, you wake up, turn the computer on, and you find another jewel! It is all around the globe so magic just never stops! It is like a new year every day with presents under the tree. Thank you, mr. Horst!

And something on the substance:

1) It would be usefull in many cases (at least for me) to have a 4th method, which would act like contain, but would fill with adjustable color spaces to the left and right (or to the up and down if it is horisontal) making the thumb a squre, but still containing the whole of the image. Like this:

post-2275-0-94617800-1416728404.jpg

2) Could you please write a bit about how you work with images. We now have options from you: pim and pia (not forgetting about core methods). How do they work together? Should we use both or just one of them and in what cases?

2 people like this

Share this post


Link to post
Share on other sites

It is incredible how it is in this PW forum, You go to sleep, you wake up, turn the computer on, and you find another jewel! It is all around the globe so magic just never stops! It is like a new year every day with presents under the tree. Thank you, mr. Horst!

So true.  :rolleyes: Thanks horst. Pia is one fine lady.

1 person likes this

Share this post


Link to post
Share on other sites

1) It would be usefull in many cases (at least for me) to have a 4th method, which would act like contain, but would fill with adjustable color spaces to the left and right (or to the up and down if it is horisontal) making the thumb a squre, but still containing the whole of the image. Like this:

2) Could you please write a bit about how you work with images. We now have options from you: pim and pia (not forgetting about core methods). How do they work together? Should we use both or just one of them and in what cases?

thanks for the nice words.

1) unfortunately Pia only assist with preparing and delegating values to the images engines. She isn't able to process images her self.

What you are requesting is "canvas", it is provided by Pim. I don't know yet if Pia dynamically should support shortcuts depending on other installed modules or not. It can become a bit confusing. On the other hand I see how comfortable it could be if Pia would assist here too.

2) I will do so when finding a bit time for it.

So true.  :rolleyes: Thanks horst. Pia is one fine lady.

yes, she is! 

pia--one-fine-lady.jpg

2 people like this

Share this post


Link to post
Share on other sites

Updated to version 4

- I had to fix the forceNew option what may be used during site develope.

- also have changed a bit on the GUI: it detects if you have Fieldtype RangeSlider installed and uses that over a regular Integer Inputfield for Quality-Setting

If you are already using it, please update too.

Edited by horst
added change to version 4
2 people like this

Share this post


Link to post
Share on other sites

Hey horst - looks awesome, but I am running php 5.3.28 on my dev server (just to pick up on things like this) and get a parse error due to:

InputfieldRangeSlider::getModuleInfo()['version'] on line 345

Something like this takes care of it:

if($modules->isInstalled('InputfieldRangeSlider')) $rangeSliderInfo = InputfieldRangeSlider::getModuleInfo();
$hasSlider = $modules->isInstalled('InputfieldRangeSlider') && version_compare($rangeSliderInfo['version'], '1.0.4', '>=');
One minor typo while I think of it:
here you can set sitewide options, - this overrides the options from site/config.php
 
This is under the main config and also the advances section. As well as the missing "s", probably also don't need the comma and the hyphen.
2 people like this

Share this post


Link to post
Share on other sites

@Adrian: thanks for the feedback. Here she is a bit to modern I believe. I will change this soon! ^-^

5 people like this

Share this post


Link to post
Share on other sites

Hi Horst,

Many times I need to output a lot of logo's. Those logo's need to have the same visual weight. Some logo's need to be wider others need to be higher. May I purpose a new method 'logo' or something ?

Pia is dancing nicely with crop contain and cover, but could you let her swing with logo ?

I have a starting point here that works great (used it many times)

3 people like this

Share this post


Link to post
Share on other sites

Hi Martijn,

you mean you have a module that outputs images of different aspect ratios in a visual weighted manner?

This would be nice to have, once we have discussed on that already.

Regarding the name 'logo' I'm not sure. Can we find a more descriptive one?

visualWeighted is to long, :lol:

1 person likes this

Share this post


Link to post
Share on other sites

Yep that is what it does and yes that's a bad name. Logo was just a name to explain the method the best I guess.

1 person likes this

Share this post


Link to post
Share on other sites

New addition to contain: weighten!
 
If you want to put some images of different aspect ratio onto a webpage and you want that they are displayed more equal visual weightened, you can use this method and options now:
.
* contain with option weighten

$image->contain('square=90, weighten=on');

.
.
There is also the possibility to prioritize portrait or landscape oriented images:
.

$image->contain('square=90, weighten=x1');  // landscapes are a bit larger than portraits

$image->contain('square=90, weighten=x2');  // landscapes are a bit more larger than portraits

$image->contain('square=90, weighten=y1');  // portraits are a bit larger than landscapes 

$image->contain('square=90, weighten=y2');  // portraits are a bit more larger than landscapes 

.
.
Have a look to this output here:
.
pia_weighten_overview.jpg
.
.
.
.
PS:
@Martijn: I have taken your code for the calculations and set the percent value hard coded to 38. This way we only need to turn weighten on or off and have not to deal with values here. The only thing I have added to the calculation is an adjustment to fit better with the largest dimension into the initial bounding box dimensions. (Github)

7 people like this

Share this post


Link to post
Share on other sites

Big thanks Horst

 

The only thing I have added to the calculation is an adjustment to fit better with the largest dimension into the initial bounding box dimensions. (Github)

 

Thats why I used a rectangular box in the Gist to control it.

1 person likes this

Share this post


Link to post
Share on other sites

Thats why I used a rectangular box in the Gist to control it.

Yes, I know and I have used it initially that way. And you also can do it now: when passing width and height instead of square, the other possible options are ignored and the result should be similar to what you have got with the gist code, but maybe a bit larger. (20%)

I thought it would be easier and less confusion for average users to just have a switch for on/off and if they define a square of 120 that they get back the largest possible image with 120px.

If you also like / need the comp param dynamically to define, it can be easily added as a 'silent' option. :)

1 person likes this

Share this post


Link to post
Share on other sites
If you also like / need the comp param dynamically to define, it can be easily added as a 'silent' option. :)
 

Great ! :-) 

Share this post


Link to post
Share on other sites

I have updated the module to Version 0.1.0 beta and it has a new addition to the weighten option that can be used together with contain.
 
The initial code I have taken for weighten calculations is from Martijn. I have changed it to simplify its usage so that you only need to specify a bounding square and have to switch it on, or additionaly prioritize landscape oriented images in two favours: x1, x2 or do the same for portrait oriented images with: y1, y2. (read more in the posts above)
 
But if you (@Martijn ;) ) like to use more different options, like with the original ImageFitBoundaries.module, you can use it by specifying different values for width and height together with the new value "comp##". For ## you set the value for compression like comp20, comp30, comp40 or whatever you like.

:)

6 people like this

Share this post


Link to post
Share on other sites

But if you (@Martijn ;) ) like to use more different options, like with the original ImageFitBoundaries.module, you can use it by specifying different values for width and height together with the new value "comp##". For ## you set the value for compression like comp20, comp30, comp40 or whatever you like.

Don't know if it is already in. But I used ImageFitBoundaries with a 'double' loop. Let me explane :-)

- looping several images through the Module and get the widest value. (No images are scaled, only values are returned)

- then I search the widest image, and take the percentage it is compaired to the box.

- I use that percentage to scale all images up.

1 person likes this

Share this post


Link to post
Share on other sites

Don't know if it is already in. But I used ImageFitBoundaries with a 'double' loop. Let me explane :-)

- looping several images through the Module and get the widest value. (No images are scaled, only values are returned)

- then I search the widest image, and take the percentage it is compaired to the box.

- I use that percentage to scale all images up.

No, it isn't in like you explained here, but it is somehow in without a double loop. But only when using a square boundary box and when the images are between the ratio aspects 1:2 -> 2:1. Images with more extreme ratio aspects are scaled none linear so that those are displayed smaller.

So, the normal usage of weighten works like your description but is assuming the ratio aspect isn't wider than 2:1 / 1:2.

When we add an additional param for the widest aspect ratio we should get the same effect as you described, I think.

You first have to run a loop through the images, fetching their aspect ratios, and afterwards pass the highest value to the contain-weighten call.

With images == photgraphs I think the average usage is well covered the way how it is setup now. But with logos it could be go much further with aspect ratios. Maybe you can drop in a small list of real logo usage aspect ratios (with extremes), so that I get a grasp of what we are talking here?

1 person likes this

Share this post


Link to post
Share on other sites

I've used the 'double loop' in pluimveeweb on the right side with the "Kennispartners" logo's. Now there's only 1 partner but when there are 3 or more (2 logo's always visible) it'll get to the widest value possible for the widest logo. 336px / 2 = 168px.

Here's some example code that will explain it better.

$compress = 40; // heavier images compress more
$x = 400; // box size, reference for image
$y = 280; // box size, reference for image
$max = 0; // calculation of the widests image, used to scale all others.

// calculate max width all images ( settings as wide as possible )
foreach($partners as $partner) {
    $image = $partner->generic_logo;
    if($image instanceof Pageimage) {
        $box = $modules->get("ImageFitBoundaries");
        $info = $box->load($image, $x, $y, $compress)->info();
        $max = $max < $info['width'] ? $info['width'] : $max;
    }
}

$percent = 168 * 100 / $max; // 2 X 168 = 336px width of the column

foreach($partners as $partner) {
    $image = $partner->generic_logo;
    
    if($image instanceof Pageimage) {
    
        $box = $modules->get("ImageFitBoundaries");
        $info = $box->load($image, $x, $y, $compress)->info();
        $width = (int) round($info['width'] / 100 * $percent);
        $height = (int) round($info['height'] / 100 * $percent);

        $options = array(
            'quality' => 100,
            'sharpening' => 'none'
        );

        $thumb = $image->size($width, $height, $options);
    }
}

I'm really happy how much you've implemented so far and I think you should not over complicate the module. I think you should leave it how it is now.

Thanks again for implementing weighten !

1 person likes this

Share this post


Link to post
Share on other sites

Thanks for giving those insights. I have made a note to the additional param for wider aspect ratios, what wouldn't be much work to implement, but will wait if other users request support for weighten with those wider aspect ratios.

Thanks for your help with this. :)

1 person likes this

Share this post


Link to post
Share on other sites

New addition: retinafy!

this was created on request from @jjozsi here in this post.
.
* retinafy

// create a pageimage with any method you like
$image = $page->images->first()->size(400, 300);  

// call retinafy on it
echo $image->retinafy();

// it outputs a markup string like this, where width and height is populated with half the sizes of the pageimage
<img src="/site/assets/files/1234/basename.400x300.jpg" width="200" height="150" alt="description" />

.
.
The default markup template has the default replacements URL, WIDTH, HEIGHT and DESCRIPTION.

<img src="[URL]" width="[WIDTH]" height="[HEIGHT]" alt="[DESCRIPTION]" />

You can change that to any markup you like in the modules Configpage!

.
.
If you have additional properties populated with pageimages in your system, you can provide an array with those property names:

// if you need custom properties in your markup, define the template in the modules config page with those placeholders, 
// please only use UPPERCASE and wrapp these [ ] around them
<img src="[URL]" width="[WIDTH]" height="[HEIGHT]" data-custom1="[CUSTOM1]" data-custom2="[CUSTOM2]" />

// call retinafy with custom property names
$customPropertyNames = array("custom1", "custom2");
echo $image->retinafy($customPropertyNames);

// it outputs a markup string like this, where width and height is populated with half the sizes of the pageimage
<img src="/site/assets/files/1234/basename.400x300.jpg" width="200" height="150" data-custom1="custom-value-1" data-custom2="custom-value-2" />

.
.

Regarding to the technique described in the article @jjozsi linked to in his post it would make much sense to use a low quality setting sitewide by defining it in the ImageSizerOptions, also available on the Pia Configpage. Otherwise, if this is not possible, you need to call your images for that you want the retinafy markup with the quality option set:

// create a pageimage with any method you like
echo $page->images->first()->size(400, 300, array("quality"=>35))->retinafy(); 
Edited by horst
5 people like this

Share this post


Link to post
Share on other sites

Hi Horst,

I've used weighten in a newsletter tool for company logo's and it working great. Thanks again for implementing it !

2 people like this

Share this post


Link to post
Share on other sites

Have updated Pia to 0.2.2 because she also was affected by the same issue as CroppableImage. Recent PW versions now (can) log modules API actions into logfile modules.txt. This is suppressed now. If you use Pia and a recent PW dev version, please update to 0.2.2. http://modules.processwire.com/modules/pageimage-assistant/

2 people like this

Share this post


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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bernhard
      Hi,
      just stumbled over a little module that i built for my last project. it helped me to test performance of my rockdatatables module to generate 3000 random json datasets and i want to share it with you. maybe it saves some time for someone.
      https://gitlab.com/baumrock/RockDummyData/
      easy example:
      $rdd = $modules->get('RockDummyData'); for($i=0; $i<15; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); echo date("d.m.Y H:i:s", $dummy->timestamp) . "<br>"; } more advanced:
      $json = new stdClass(); $json->data = array(); $rdd = $modules->get('RockDummyData'); for($i=0; $i<3000; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); $obj = new stdClass(); $obj->name = $dummy->forename . ' ' . $dummy->surname; $obj->position = $dummy->job; $obj->office = $dummy->city; $obj->color = $dummy->color; $obj->start_date = new stdClass(); $obj->start_date->display = date('d.m.Y',$dummy->timestamp); $obj->start_date->sort = $dummy->timestamp; $obj->salary = rand(0,10000); $json->data[] = $obj; } echo json_encode($json); you have to store your random datasets on your own into the /data folder. there are several services for creating all kinds of random data on the web - if you know one service that allows sharing those datasets let me know and i can include common needed data into the module
    • By AndySh
      Hello!
      I need your assistance please. I purchased the module FormBuilder. Unfortunately, the module discontinued delivering customer submissions to e-mail box specified in the module settings. Direct mailing to the e-mail box works OK. The module settings stays the same and are correct, like "Send e-mail to administrator(s) is checked. The last version of FormBuilder 3.0 has been installed. Please advise how to resolve the issue becase I cannot get orders from customers anymore (((
    • By kixe
      As described in this post (https://processwire.com/talk/topic/8551-custom-urls-for-pages/?p=82742) the option 'Name Format Children' under the tab 'Family' in template settings doesn't work properly and also not as expected. I had a look inside the code and made some changes which are working properly, which offers much more options, more consistency and less code too.

      The result is the following. You have 3 Options for generating name and title, which could be combined in endless variations.
      Name is always derived from title, same like creating pages manually.
      type date: if function detects # character anywhere in the string, conversion will be: deletion of # and string will be used as format parameter for PHP date() function type field: if string is a fieldname of the parent page the value of this field will be used type string: if string doesn't fit to the 2 preceeding it will be taken as it is All parts (separated by comma) will be composed in the order of setting. You can use unlimited numbers of parts

      I made a pull request on github: https://github.com/ryancramerdesign/ProcessWire/pull/831

      Example screenshots

      Setting ...


      will result in


       
    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
       
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend