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

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

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
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • 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:
       
×
×
  • Create New...