Jump to content

Release: Thumbnails


apeisa

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

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

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

  • 4 weeks later...

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.

Link to comment
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
Link to comment
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}' />";
Link to comment
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

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

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

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

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

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

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

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
×
×
  • Create New...