Jump to content

Pia - Pageimage Assistant


horst
 Share

Recommended Posts

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

 

  • Like 36
Link to comment
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?

  • Like 2
Link to comment
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.

  • Like 1
Link to comment
Share on other sites

On 11/23/2014 at 8:47 AM, Ivan Gretsky said:

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 by herself.

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.

On 11/23/2014 at 4:54 PM, Peter Knight said:

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

yes, she is! 

pia--one-fine-lady.jpg

  • Like 2
Link to comment
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
  • Like 2
Link to comment
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.
  • Like 2
Link to comment
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)

  • Like 3
Link to comment
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:

  • Like 1
Link to comment
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)

  • Like 7
Link to comment
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. :)

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

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.

:)

  • Like 6
Link to comment
Share on other sites

  • 2 weeks later...

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.

  • Like 1
Link to comment
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?

  • Like 1
Link to comment
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 !

  • Like 1
Link to comment
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. :)

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

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
  • Like 5
Link to comment
Share on other sites

  • 4 weeks later...

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/

  • Like 2
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...