Recommended Posts

Inspired by the "max megapixels" option for the client-side image resizer, I made a simple module that adds target megapixel resizing for Pageimages.

Image Megapixels

Adds a method for Pageimages that resizes to a target megapixel value.

Example use

You are creating a lightbox gallery of images with different aspect ratios. For the enlargements, rather than setting a fixed maximum width or height you want all the enlargements have the same size in terms of area, allowing a panoramic image to be wider than a square image, for instance.

The effect of resizing three different aspect ratios by the same megapixel target value can be seen in the screenshot below:

megapixels

Installation

Install the Image Megapixels module.

API

// basic usage
$pageimage = $pageimage->megapixels(float $megapixels);

// usage with all arguments
$pageimage = $pageimage->megapixels(float $megapixels, array $options = []);

Example:

foreach($page->images as $image) {
    echo "<img src='$image->megapixels(0.8)->url' alt='$image->description'>"
}

If needed you can supply an array of options for Pageimage::size() as a second argument.

 

https://github.com/Toutouwai/ImageMegapixels

  • Like 12

Share this post


Link to post
Share on other sites

Thank you for this, but for now I do not see in what situation would be useful to have images with different sizes but the same no of pixels (area)... what was your motivation for this module ? 

Share this post


Link to post
Share on other sites

@adrianromega, did you see the "Example use" section above?

To expand on this... it's useful in any situation where you want to be fair to a group of images with different aspect ratios. Take the three images shown in the screenshot above. If these images had been resized using maxSize(800,800) for instance, photo 2 (the square image) would be larger than the others in total area - it would contain the most image data.

Now suppose you're running a competition on your website where visitors can vote for the best photo. The three images above have been submitted by three different photographers. If you are resizing by maxSize() rather than megapixels then it's not fair on photographers 1 and 3 that their images are shown smaller than the image from photographer 2.

  • Like 3

Share this post


Link to post
Share on other sites

Great for sponsor logos too so that no-one feels gipped.

  • Like 4

Share this post


Link to post
Share on other sites

Hi @Robin S, congrats to one more nice module! And I totally understand why you created it. I also (wanted to) use such a feature in different scenarios. Therefor once I added the "weighten" option to the PIA module.

Hopefully you don't mind my following propagation of an alternative way to apply such a functionality. Maybe it is usefull for some people to have a different way to define / calculate / imagine the resulting images.

You call it Megapixels, Pia uses image pixel dimensions for width & height or a single dimension for squares, defining a bounding box and get the images contained & weightened into that box. Additonally Pia handles one out of four values to the weighten-option to prioritize the landscape or portrait images in two ways: 

 

So, what you wanted was allready available in the modules directory for about three years. But I believe, when seeing all your modules, you have had fun building and sharing it.

OT:
For me, the last two years it is not possible to keep track of all the good new stuff coming into the core and from community members (like you). Some years ago, it felt doable for me. Lately I also found "a new possibility" to do things that was allready three years available. Even I had read it in the past and bookmarked it under my other several hundred PW links, it got out of focus. If somebody know a good way to keep track and or archive all the good stuff from here, (besides the few things that get mentions in the weekly news & blog posts), please share. :)

  • Like 4

Share this post


Link to post
Share on other sites
9 minutes ago, horst said:

So, what you wanted was allready available in the modules directory for about three years. But I believe, when seeing all your modules, you have had fun building and sharing it.

:). Yeah, @Robin S has been on fire! I've learnt a lot about Inputfields and Hooks from his work.

 

10 minutes ago, horst said:

For me, the last two years it is not possible to keep track of all the good new stuff coming into the core and from community members (like you). Some years ago, it felt doable for me. Lately I also found "a new possibility" to do things that was allready three years available. Even I had read it in the past and bookmarked it under my other several hundred PW links, it got out of focus.

That's me! :P.

  • Like 3

Share this post


Link to post
Share on other sites
11 hours ago, horst said:

Therefor once I added the "weighten" option to the PIA module.

Ah, I should have known there would be something in PIA for this - it's the real Swiss Army Knife for images. :-)
I really need to have a proper explore of that module. (I think it's the state of the docs that has been putting me off - maybe you could consolidate/tidy everything into the GitHub readme?)

11 hours ago, horst said:

For me, the last two years it is not possible to keep track of all the good new stuff coming into the core and from community members

I have a very primitive system. For modules I'm interested in I have a spreadsheet with name, category, link, brief description of what it does (in my own words). But I often forget to update it with new modules and just try to rely on memory.

For forum snippets (and links to the original post) I just have a folder with a bunch of text files in it. The text files are named according to what the snippet is about. Then when I'm looking for something I use the quick filter feature in my file manager (XYplorer).

  • Like 3

Share this post


Link to post
Share on other sites

This is OT, sorry, but if there is enough interest, the last few posts could be moved to a dedicated Topic...

12 hours ago, Robin S said:

I have a very primitive system. For modules I'm interested in I have a spreadsheet with name, category, link, brief description of what it does (in my own words). But I often forget to update it with new modules and just try to rely on memory.

I do not have to much spare time this year but I would love to help anyone interested in developing an alternative module directory. For example there are such things for WP:

ProcessWire is a native cataloging system, as we all know. So it would not take too much time for a few experienced devs to come up with something useful and opensource. What I could contribute is UI/UX design and creating and editing content, for example. We've read lots of other posts about willing to help to boost the ProcessWire documentation, so I guess there should be enough of us to turn it into a success story.

12 hours ago, Robin S said:

For forum snippets (and links to the original post) I just have a folder with a bunch of text files in it. The text files are named according to what the snippet is about. Then when I'm looking for something I use the quick filter feature in my file manager (XYplorer).

This site I propose could be a "module+snippets finder", ie. a "ProcessWire Solutions" site, meaning both modules and snippets could be in the database, making integrated "solution" searches possible.

Anybody up to the challenge?

Edited by szabesz
typos
  • Like 2

Share this post


Link to post
Share on other sites
22 hours ago, szabesz said:

This is OT, sorry, but if there is enough interest, the last few posts could be moved to a dedicated Topic...

I have to agree: this is a good discussion, but doesn't belong to module support thread. Any mods up to that? ;)

22 hours ago, szabesz said:

This site I propose could be a "module+snippets finder", ie. a "ProcessWire Solutions" site, meaning both modules and snippets could be in the database, making integrated "solution" searches possible.

I hope I'm not causing any unnecessary confusion – and I may not see the full picture yet, so perhaps I'm missing the point entirely – but when it comes to snippets, there's already https://processwire-recipes.com/. If you have useful snippets for common tasks etc. I'd suggest submitting them there.

Similarly I'm leaning towards collecting ideas for improving the existing modules directory rather than creating a competing platform. In the 2018 roadmap post Ryan listed modules directory as one focus point for this year, and I'm sure he'd be happy to get some feedback on exactly how it could be improved.

  • Like 4

Share this post


Link to post
Share on other sites
14 hours ago, teppo said:

I have to agree: this is a good discussion, but doesn't belong to module support thread. Any mods up to that? ;)

I hope I'm not causing any unnecessary confusion – and I may not see the full picture yet, so perhaps I'm missing the point entirely – but when it comes to snippets, there's already https://processwire-recipes.com/. If you have useful snippets for common tasks etc. I'd suggest submitting them there.

Similarly I'm leaning towards collecting ideas for improving the existing modules directory rather than creating a competing platform. In the 2018 roadmap post Ryan listed modules directory as one focus point for this year, and I'm sure he'd be happy to get some feedback on exactly how it could be improved.

I agree that this is a good discussion and needs to be continued somewhere (I'm not the one for moving things, I haven't figured how to do it right yet). 

I have an upcoming blog project whose sole purpose is to talk about ProcessWire's many features.  Once someone has moved this conversation to a new area, I can further elaborate on what I am working towards.  With that said, I also agree with what @teppo seems to be saying.

  • Like 2

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 Anssi
      A simple module to enable easy navigation between the public and the admin side of the site. After installation a green bar will appear to the upper side of the screen, containing a few navigation elements and displaying the PW version number.
      Heavily inspired by @apeisa's great AdminBar (Thanks!). I needed a bit simpler tool for my projects and as a result, this was made. Available on GitHub .

    • By Sebi
      I've created a small module which lets you define a timestamp after which a page should be accessible. In addition you can define a timestamp when the release should end and the page should not be accessable any more.
      Github: https://github.com/Sebiworld/PageAccessReleasetime
      Usage
      PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules
      After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.
      Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.
      If you have $config->pagefileSecure = true, the module will protect files of unreleased pages as well.
      How it works
      This module hooks into Page::viewable to prevent users to access unreleased pages:
      public function hookPageViewable($event) { $page = $event->object; $viewable = $event->return; if($viewable){ // If the page would be viewable, additionally check Releasetime and User-Permission $viewable = $this->canUserSee($page); } $event->return = $viewable; } To prevent access to the files of unreleased pages, we hook into Page::isPublic and ProcessPageView::sendFile.
      public function hookPageIsPublic($e) { $page = $e->object; if($e->return && $this->isReleaseTimeSet($page)) { $e->return = false; } } The site/assets/files/ directory of pages, which isPublic() returns false, will get a '-' as prefix. This indicates ProcessWire (with activated $config->pagefileSecure) to check the file's permissions via PHP before delivering it to the client.
      The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.
      public function hookProcessPageViewSendFile($e) { $page = $e->arguments[0]; if(!$this->canUserSee($page)) { throw new Wire404Exception('File not found'); } } Additionally we hook into ProcessPageEdit::buildForm to add the PageAccessReleasetime fields to each page and move them to the settings tab.
      Limitations
      In the current version, releasetime-protected pages will appear in wire('pages')->find() queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with $page->viewable() wether the page can be accessed. $page->viewable() returns false, if the page is not released yet.
      If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request!
    • By David Karich
      Thanks to the great Pro module "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use this module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      With this proof of concept I have created a module which adds the feature to copy a repeater item to the clipboard so that you can paste this item to another page with the same repeater field. The module has been developed very rudimentarily so far. It is currently not possible to copy nested items. There is also no check of Min/Max. You can also only copy items that have the same field on different pages. And surely you can solve all this more elegantly with AJAX. But personally I lack the deeper understanding of the repeaters. Also missing on the Javascript side are event triggers for the repeaters, which would make it easier. Like e.g. RepeaterItemInitReady or similar.
      it would be great if @ryan would implement this functionality in the core of RepeaterMatrix. I think he has better ways to implement this. Or what do you think, Ryan?
      Everybody is welcome to work on this module and improve it, if it should not be integrated into the matrix core. Therefore I put it for testing and as download on GitHub: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDublicate
      You can best see the functionality in the screencast: 
       
    • By anderson
      Hi,
      Please take a look at this:
      https://templatemag.com/demo/Good/
      The upper nav bar, including dropdowns like "pages" and "portfolios", what do you call this whole thing? At first I guess it's called "dropdown nav bar", but seems not.
      AND of course, what's the simplest way/module to achieve this in PW?
      Thanks in advance.
    • By Sebi2020
      Hey, I'm new and I created a simple module for tagging pages because I didn't found a module for it (sadly this is not a core feature). This module is licensed under the GPL3 and cames with absolutly no warranty at all. You should test the module before using it in production environments. Currently it's an alpha release. if you like the module or have ideas for improvements feel free to post a comment. Currently this fieldtype is only compatible with the Inputfield I've created to because I haven't found  an Inputfield yet, that returns arrays from a single html input.
      Greetings Sebi2020
      FieldtypeTags.zip.asc
      InputfieldTagify.zip
      InputfieldTagify.zip.asc
      FieldtypeTags.zip