Jump to content
apeisa

Release: Thumbnails

Recommended Posts

but not working with that image again but with the original image to get the best quality.

This line clarified it. Because you can do everything you want using the <img> tag / CSS technique, up until that line quoted above. Though it is a bit of a technicality, so long as your 2nd crop is going to be smaller than the first. In fact, a 400x300 image displayed at 200px width and CSS vertically centered and overflow:hidden at 100px height will technically be higher quality than an image literally at dimensions 200x100. But if you are concerned about file size, then the actual 200x100 image will be more desirable. Personally, I don't have a high DPI screen on my main computer (just my phone), but supporting high DPI now makes us more future proof, as it'll probably be expected everywhere in a couple years from now. So if it were me, I'd go for the CSS technique. But you can get the result you want by taking your 400x300 crop and using the ImageSizer class to make a copy at 200x100:

$file1 = '/path/to/your/400x300/file.jpg';
$file2 = dirname($file1) . '/200x100-' . basename($file1); 
if(!is_file($file2) || filemtime($file2) < filemtime($file1)) {
  copy($file1, $file2); 
  $sizer = new ImageSizer($file2);
  $sizer->resize(200, 100); 
}
// file2 is ready to display

Share this post


Link to post
Share on other sites

Hi Ryan,

thanks for putting so much time into this!

While definitely seeing the advantages of the CSS approach, I still want to go with the traditional style of image editing here (to keep bandwith usage low, etc).

The solution you proposed is a handy workaround, but I'd still have the problem, that I'd be generating an image from a slightly bigger image while I have the original (with a possibly huge resolution) lying around unused which bothers me in a way, to I lose quality that might have been there.

I still think, a great addition to the module would be to store the cropping metadata in the DB. This wouldn't only enable to recrop from already cropped images (without loosing quality) but also the case, where you want to change image sizes slightly after you have used the ImageCrop a lot already.

Imagine you do a redesign of a page involving slightly resizing your thumbnails and/or changing the aspect ratio. This would involve then doing some quirky workaround with your old thumbnails, possibly involving a lot of unnecessary bandwith, because you don't want to loose the images you have cropped so far. With the crop data in the db, it would be a breeze to add some kind of batch processing to reprocess your images with the sections, you have manually chosen, from the originals.

Share this post


Link to post
Share on other sites
The solution you proposed is a handy workaround, but I'd still have the problem, that I'd be generating an image from a slightly bigger image while I have the original (with a possibly huge resolution) lying around unused which bothers me in a way, to I lose quality that might have been there.

If nothing is going to get stretched to reach the target, and the source is bigger than the target, it's kind of splitting hairs. My eyes won't be able to tell the difference at least (not that I have good eyes). I don't disagree that the capability is desirable and that there will be those cases where one would have better than the other. But everything costs time and money to do, and so the developer of this module (or the developer of any module) often has to focus on their own needs. If it's not something the developer will use themselves, it can be too costly to develop without a sponsor or collaborator. If this is something you believe in and are interested in developing, you can always update the module and submit a pull request, or offer to sponsor the feature with the developer. Sooner or later someone will have a similar need, so it's also good to get the ideas down here as you have, as another developer may come along and implement it too. 

Share this post


Link to post
Share on other sites

Hi everyone, this is my first post here, so let me start with a big thank you. These past few days I duplicated almost all the functionality of a site I've been working on for much longer in Drupal, and it's much leaner and nicer, and without 27 extra modules.

I was looking for something similar that Marc is talking about. Drupal has a module called "imagefield focus", where you can specify a region that you want in all of your cropped versions, regardless of their size or aspect ratio. It also lets to specify another (bigger) region that you don't want to go outside of; it's good if the original image has a border that you want to get rid of. The awesome thing about this approach is that the API would remain the same, except $image->size(...) would now work with those boundaries. This, of course, requires the boundaries stored in the database, and also a timestamp to know when to update the already rendered images.

  • Like 3

Share this post


Link to post
Share on other sites

@tibs:

Thanks a lot for pointing this out, I didn't see this before, but I think it's an elegant solution for an all-too-common problem and should work for a lot of use cases. It would definitely be worth the effort to develop this as a module of its own or integrate this into Thumbnail as an option, where you can choose which flavour of cropping you want for every field. Would be a lot of work though.

@ryan:

I'm completely aware that this is not coming into existence magically just because I want it. Just writing down my ideas here, and I hope to find the time for looking closer into this on my own. But I also wouldn't be offended if anyone likes the idea and gives it a try.  ;)

  • Like 1

Share this post


Link to post
Share on other sites

Hi there,

i receive the following error:

Error	Exception: Method Pageimages::getThumb does not exist or is not callable in this context (in /home/xxx/public_html/xxx.de/wire/core/Wire.php line 232)

I am calling the thumbnail as follows:

$thumb = $page->mitglied_foto->getThumb('thumbnail');
echo "<img class='mitglied_image' src='{$thumb->url}' alt='{$page->mitglied_foto->description}' />";

Am i doing something wrong?

I am using one of the latest dev versions of PW.

Share this post


Link to post
Share on other sites

Doolak, you are trying to get thumb from Pageimages (bunch of images) instead of single image.

Does this work: $page->mitglied_foto->first()->getThumb('thumbnail');

Or alternatively edit mitglied_foto field and set it to allow only one image (then it returns that single image in api instead of Pageimages).

  • Like 1

Share this post


Link to post
Share on other sites

Thanks, apeisa - you were right. I have set the field to allow just one image and the error is gone.

Now i have just to find out why it is displayed now as a 1x1 Pixel image ;-)

Share this post


Link to post
Share on other sites

Ok, got it: it has to be:

echo "<img class='mitglied_image' src='{$thumb}' alt='{$page->mitglied_foto->description}' />";

not:

echo "<img class='mitglied_image' src='{$thumb->url}' alt='{$page->mitglied_foto->description}' />";

Share this post


Link to post
Share on other sites

I have just run into an issue with Thumbnails which has to be an issue with my Dev box, but I am not sure what.

Basically, if I try and upload an image, it doesn't work - the name of the image appears, crossed out with the red X symbol and a notice that says "there is no thumb called:"

The standard image field works fine.

What should I be looking for?

Joss

Share this post


Link to post
Share on other sites

Have you defined thumbnails? Saving the field might also help.

Share this post


Link to post
Share on other sites

Hi apeisa

Yep, three different thumbnails, commas in the right places. I have used this loads.

I just checked with another installation on the same box and it is the same problem - but I don't get it on my production server.

So it has to be something with my local box - but damned if I know what.

Share this post


Link to post
Share on other sites

Memory? Have you changed the field from image to crop image?

Share this post


Link to post
Share on other sites

Hi Soma

No it was a crop image to start with. 

All pretty normal stuff to be honest - haven't done anything clever

Share this post


Link to post
Share on other sites

I have just tried with a different crop image on another installation on the same box, and it is the same problem.

Normal images work fine.

So it must be something that crop image needs in apache that I haven't got?  I am guessing wildly!

Share this post


Link to post
Share on other sites

Nope

The dev box is Ubunto server with webmin/virtualmin installed.

Recent versions of apache, php - all installed as standard.

Share this post


Link to post
Share on other sites

er, so how do I get round that?

Since this error is on the module upload itself. 

Interestingly, when it says There is no thumb called ... there is no name after the word called.



I checked directory permissions, by the way, and they seem okay. The images field is uploading fine.

Share this post


Link to post
Share on other sites

Ah, sorry. This is where the problems come from. For some reason it parses the settings differently. Try to debug these: https://github.com/apeisa/Thumbnails/blob/master/InputfieldCropImage/InputfieldCropImage.module#L76

What you have on $crops after line 76? What you have in foreach? And finally why it leaves $prefix empty.

Share this post


Link to post
Share on other sites

ummm

not sure what you mean ....

(remember, me not a programmer!)

Share this post


Link to post
Share on other sites

Er .... is this a problem with 2.3?

I have just noticed that I don't have this problem on a system running 2.2.12 on the same box.

EDIT: I mean, the difference between 2.2.1.2 and 2.2.1.3

Share this post


Link to post
Share on other sites

HI Apeisa

I have just tested Thumbnails with a standard install of 2.2.13 on a normal shared server, and it is coming up with the same problem - just not uploading images.

Here is a screenshot

cropimage.jpg

As soon as the file seems to upload, the error in red appears, and the file has not uploaded.

Working fine in 2.2.12

Edit: still not working with 2.2.14

Share this post


Link to post
Share on other sites

Okay, That is interesting.

I had set it up with different thumbnail values and it didn't work.

But you are right - re-saving the field makes it work.

I thought I had already tried that, mostly because I had changed the default values for three others. But perhaps just changing the values immediately after creating the field and then saving was not enough - it had to be saved again.

having now got it working, I have tried changing values again, but this is okay - one save is enough. So it must be down to that first save after creating the field

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 d'Hinnisdaël
      Happy new year, everybody 🥬
      I've been sitting on this Dashboard module I made for a client and finally came around to cleaning it up and releasing it to the wider public. This is how it looks.
      ProcessWire Dashboard

      If anyone is interested in trying this out, please go ahead! I'd love to get some feedback on it. If this proves useful and survives some real-world testing, I'll add this to the module directory.
      Download
      You can find the latest release on Github.
      Documentation
      Check out the documentation to get started. This is where you'll find information about included panel types and configuration options.
      Custom Panels
      My goal was to make it really simple to create custom panels. The easiest way to do that is to use the panel type template and have it render a file in your templates folder. This might be enough for 80% of all use cases. For anything more complex (FormBuilder submissions? Comments? Live chat?), you can add new panel types by creating modules that extend the DashboardPanel base class. Check out the documentation on custom panels or take a look at the HelloWorld panel to get started. I'm happy to merge any user-created modules into the main repo if they might be useful to more than a few people.
       Disclaimer
      This is a pre-release version. Please treat it as such — don't install it on production sites. Just making sure 🍇
      Roadmap
      These are the things I'm looking to implement myself at some point. The wishlist is a lot longer, but those are the 80/20 items that I probably won't regret spending time on.
      Improve documentation & add examples ⚙️ Panel types Google Analytics ⚙️ Add new page  🔥 Drafts 🔥 At a glance / Page counter 404s  Layout options Render multiple tabs per panel panel groups with heading and spacing between ✅ panel wrappers as grid item (e.g. stacked notices) ✅ Admin themes support AdminThemeReno and AdminThemeDefault ✅ Shortcuts panel add a table layout with icon, title & summary ✅ Chart panel add default styles for common chart types ✅ load chart data from JS file (currently passed as PHP array) Collection panel support image columns ✅ add buttons: view all & add new ✅
    • By Pip
      Hi everyone!
      I'm trying out the Login/Register module for my site. Noted that the module assigns the newly registered user to login-register role. 
      Once you modify the login-register role's permissions, particularly adding page-edit, the new member role will be set to guest. 
      Thing is I'd like to grant my new users the power to create their own pages. Any advice? 
      Thanks. 
    • By Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-07-03 -- SnipWire 0.8.7 (beta) released! Fixes some small bugs and adds an indicator for TEST mode 2020-04-06 -- SnipWire 0.8.6 (beta) released! Adds support for Snipcart subscriptions and also fixes some problems 2020-03-21 -- SnipWire 0.8.5 (beta) released! Improves SnipWires webhooks interface and provides some other fixes and additions 2020-03-03 -- SnipWire 0.8.4 (beta) released! Improves compatibility for Windows based Systems. 2020-03-01 -- SnipWire 0.8.3 (beta) released! The installation and uninstallation process has been heavily revised. 2020-02-08 -- SnipWire 0.8.2 (beta) released! Added a feature to change the cart and catalogue currency by GET, POST or SESSION param 2020-02-03 -- SnipWire 0.8.1 (beta) released! All custom classes moved into their own namespaces. 2020-02-01 -- SnipWire is now available via ProcessWire's module directory! 2020-01-30 -- SnipWire 0.8.0 (beta) first public release! (module just submitted to the PW modules directory) 2020-01-28 -- added Custom Order Fields feature (first SnipWire release version is near!) 2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Multi currency support Custom order and cart fields Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  

       
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By Sten
      Hello
      Till now I hacked something with the twig template but it works no more with new PW versions so I look forward to create a module. I am working on a site in multiple languages : French, English, Italian, German, Spanish, Portuguese, Hebrew, Russian. The new posts are entered in any language with a field for language. Till now, I got twig files to get the translations with constants defined for each part of the pages.
      So I'd like to create a module to include theses files added according to the url /fr/en/...
      Have you some observations to do before I begin about the direction to take ?
      Thank you
    • By ukyo
      Mystique Module for ProcessWire CMS/CMF
      Github repo : https://github.com/trk/Mystique
      Mystique module allow you to create dynamic fields and store dynamic fields data on database by using a config file.
      Requirements
      ProcessWire 3.0 or newer PHP 7.0 or newer FieldtypeMystique InputfieldMystique Installation
      Install the module from the modules directory:
      Via Composer:
      composer require trk/mystique Via git clone:
      cd your-processwire-project-folder/ cd site/modules/ git clone https://github.com/trk/Mystique.git Module in live reaction with your Mystique config file
      This mean if you remove a field from your config file, field will be removed from edit screen. As you see on youtube video.
      Using Mystique with your module or use different configs path, autoload need to be true for modules
      Default configs path is site/templates/configs/, and your config file name need to start with Mystique. and need to end with .php extension.
      Adding custom path not supporting anymore !
      // Add your custom path inside your module class`init` function, didn't tested outside public function init() { $path = __DIR__ . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR; Mystique::add($path); } Mystique module will search site/modules/**/configs/Mystique.*.php and site/templates/Mystique.*.php paths for Mystique config files.
      All config files need to return a PHP ARRAY like examples.
      Usage almost same with ProcessWire Inputfield Api, only difference is set and showIf usage like on example.
      <?php namespace ProcessWire; /** * Resource : testing-mystique */ return [ 'title' => __('Testing Mystique'), 'fields' => [ 'text_field' => [ 'label' => __('You can use short named types'), 'description' => __('In file showIf working like example'), 'notes' => __('Also you can use $input->set() method'), 'type' => 'text', 'showIf' => [ 'another_text' => "=''" ], 'set' => [ 'showCount' => InputfieldText::showCountChars, 'maxlength' => 255 ], 'attr' => [ 'attr-foo' => 'bar', 'attr-bar' => 'foo' ] ], 'another_text' => [ 'label' => __('Another text field (default type is text)') ] ] ]; Example:
      site/templates/configs/Mystique.seo-fields.php <?php namespace ProcessWire; /** * Resource : seo-fields */ return [ 'title' => __('Seo fields'), 'fields' => [ 'window_title' => [ 'label' => __('Window title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'attr' => [ 'placeholder' => __('Enter a window title') ] ], 'navigation_title' => [ 'label' => __('Navigation title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'showIf' => [ 'window_title' => "!=''" ], 'attr' => [ 'placeholder' => __('Enter a navigation title') ] ], 'description' => [ 'label' => __('Description for search engines'), 'type' => Mystique::TEXTAREA, 'useLanguages' => true ], 'page_tpye' => [ 'label' => __('Type'), 'type' => Mystique::SELECT, 'options' => [ 'basic' => __('Basic page'), 'gallery' => __('Gallery'), 'blog' => __('Blog') ] ], 'show_on_nav' => [ 'label' => __('Display this page on navigation'), 'type' => Mystique::CHECKBOX ] ] ]; Searching data on Mystique field is limited. Because, Mystique saving data to database in json format. When you make search for Mystique field, operator not important. Operator will be changed with %= operator.
      Search example
      $navigationPages = pages()->find('my_mystique_field.show_on_nav=1'); $navigationPages = pages()->find('my_mystique_field.page_tpye=gallery');
×
×
  • Create New...