Jump to content

Release: Thumbnails


apeisa

Recommended Posts

It would be great if imageSizerOptions like in $image->size() would be available as well:

$image->getThumb('thumbnail', $options);

Maybe, but as of Thumbnails is a visual Tool, I wish to have it like in my dirty Hack.

plus one additional feature: If you have created a Thumb and quality isn't what you have expected, when you go back to recreate it, the CropRectangle should be placed automaticaly at its place, so you have only to select a different quality and / or sharpening pattern.

(Just a dream, - but sometimes they become true) :)

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Sorry, I don't understand how to use in my templates :undecided:
I have the "main_image" field using "CropImage" type. I set: thumbnail,310,175
What code I should to use if I want to display this field in a list of pages and in one individual page?
Thanks in advanced

Fernando

Link to comment
Share on other sites

Sorry, I don't understand how to use in my templates :undecided:

I have the "main_image" field using "CropImage" type. I set: thumbnail,310,175

What code I should to use if I want to display this field in a list of pages and in one individual page?

Thanks in advanced

Fernando

thumbnail in this case is the name you reference in the template.

The first() method selects the first image in the list of images attached to the page.

$page->main_image->first()->getThumb('thumbnail');

if it is "portait-small,300,500" it woud be 

$page->main_image->first()->getThumb('portrait-small');
  • Like 1
Link to comment
Share on other sites

Very clear, however it doesn't work for me.

I'm getting an error in the template. It's strange because in the Admin side, this module works fine

Error:     Exception: Method Pageimage::first does not exist or is not
callable in this context (in C:\xampp\htdocs\test\wire\core\Wire.php line 232)

#0 [internal function]: Wire->__call('first', Array)
#1 C:\xampp\htdocs\test\site\templates\trabajo.php(16): Pageimage->first()
#2 C:\xampp\htdocs\test\wire\core\TemplateFile.php(125): require('C:\xampp\htdocs...')
#3 [internal function]: TemplateFile->___render()
#4 C:\xampp\htdocs\test\wire\core\Wire.php(271): call_user_func_array(Array, Array)
#5 C:\xampp\htdocs\test\wire\core\Wire.php(229): Wire->runHooks('render', Array)
#6 [internal function]: Wire->__call('render', Array)
#7 C:\xampp\htdocs\test\wire\modules\PageRender.module(250): TemplateFile->render()
#8 [internal function]: PageRender->___renderPage(Object(HookEvent))
#9 C:\xampp\htdocs\test\wire\core\Wire.php(271): call_user_func_array(Array, Array)
#10 C:\xampp\htdocs\test\wire\core\Wire.php(229): Wire->runHooks('renderPage', Array)
#11 [internal function]: Wire->__call('renderPage', Array)
#12 C:\xam

This error message was shown because you are logged in as a Superuser. Error has been logged.  

Any idea?

Link to comment
Share on other sites

This is because it's set to be a single image field, so just don't use first() or eq(0).

Or to make it a multi images field go to the the field settings / Details and set Maximum files allowed to 0 (infinite) or any number greater that 0.

  • Like 2
Link to comment
Share on other sites

first() or eq(0) for an array of (multiple) images, and leave it off if it's a single image.

Single image:

echo $page->main_image->getThumb('thumbnail');

Edit: adrian beat me to it =)

  • Like 2
Link to comment
Share on other sites

Sorry, one more thing - is it possible (or should I say, can you make it possible) to set just one dimension, or perhaps neither (set them to 0). I would like to allow the user the ability to crop freeform, and then resize automatically (if one dimension set), or later through a template if no dimensions set. I think this would be really useful - often in layouts you want all images the same width, but you don't care about height, and vice versa.

First of all, thank you for this module apeisa (and your sponsor!). I’m also in the need of having this freeform cropping functionality, the only thing you need to do is to set the aspectRatio of jCrop to 0. Thing is, when I try to enter this in the config file:

thumbnail,0,0

The page I use the field on will give me this error:

Width and/or height not found for thumb: thumbnail

It would be a nice piece of extra functionality to have in there and it seems super simple to do it this way. I’ve been going through the module files but I havent found a way around this yet, any insights from you guys?

Thanks in advance!

Thijs

Link to comment
Share on other sites

Found it, it’s in here: (FieldtypeCropImage.module)

if ($this->w < 1 || $this->h < 1) {
    throw new WireException(sprintf($this->_("Width and/or height not found for thumb: %s"), $thumb));
    return;
}    
I’ll see if I can rewrite this to check for the presence of the values and not for them to be smaller than 1. I think this piece of code casts an empty value (no dimensions entered in config) to 0
$this->w = (int) $crop[1];
$this->h = (int) $crop[2];

So I can’t use is_numeric or is_empty to check if there is a value present. And even if I work around this for the time being (by commeting out the width/height check), the crop I make is not being saved.

Link to comment
Share on other sites

Sorry guys, I am having busy week and not able to take look. If someone's figures way to support freeform (full or half) cropping, without braking backwards compatibility, I am happy to merge.

Link to comment
Share on other sites

Hi apeisa,

Thanks for your reply! These are the changes I needed to do in order to make it work:

Comment out this line in FieldtypeCropImage.module

if ($this->w < 1 || $this->h < 1) {
  throw new WireException(sprintf($this->_("Width and/or height not found for thumb: %s"), $thumb));
  return;
}  


And I’ve changed the if / condition in ProcessCropImage.module:

if (!$prefix || $targetWidth == 0 || $targetHeight == 0) {
    $targetHeight = (int) $crop['h'];
    $targetWidth = (int) $crop['w'];
}
 

Not sure if this is the proper way to do it, I guess a second set of eyes would be good before I propose to merge anything!

Link to comment
Share on other sites

Hi apeisa,

Thanks for your reply! These are the changes I needed to do in order to make it work:

Comment out this line in FieldtypeCropImage.module

if ($this->w < 1 || $this->h < 1) {
throw new WireException(sprintf($this->_("Width and/or height not found for thumb: %s"), $thumb));
  return;
}  


And I’ve changed the if / condition in ProcessCropImage.module:

if (!$prefix || $targetWidth == 0 || $targetHeight == 0) {
    $targetHeight = (int) $crop['h'];
    $targetWidth = (int) $crop['w'];
}

Not sure if this is the proper way to do it, I guess a second set of eyes would be good before I propose to merge anything!

Link to comment
Share on other sites

  • 2 weeks later...

I'd like to report an issue:

 

Here is screenshot of what I get when I click on the Profile link. post-1067-0-17449500-1372318808_thumb.pn

Do duplicate the issue:

1. Create new field with type CropImage

2. Assign this field to the "user" template (system template)

3. Go to Modules -> User Profile module.

4. Check the new field you created so that it will show up in the Profile screen.

3. Click on Profile link - right beside Logout. You should be able to see the Profile screen... for now.

4. Now upload a new thumbnail.

5. Save.

6. Meet the screenshot above.

This is the list of site modules I have installed:

AdminBar
AfterSaveActions
FieldtypeCropImage
FieldtypeTemplates.module
MarkupTwitterFeed
ModulesManager
PageEditFoldStatus
PageEditPerRole
PageEditPerUser
PageListPin
PagesCreatedEdit.module
ProcessLatestComments
ProcessPageDelete
ProcessSelectorTest
README.txt
TextformatterVideoEmbed
 
 
Everything goes to normal if you uncheck the thumbnail field from displaying in the User Profile config module.
 
Link to comment
Share on other sites

Thanks for the report. It will take few days before I can test this, so if anyone can try this with default install without any other modules or custom admin theme it would definitely help.

Link to comment
Share on other sites

  • 4 weeks later...

**EDIT**

The problem is solved. I basically hadn't upload all the relevant files for the module. Basic error, my apologies.

ps

It's a very good module, I'm happy!

**//EDIT**

Hello. I've just started using this promising-looking module on the latest build of ProcessWire but I'm having some problems fairly early on.

I installed the module as instructed. Created a new Image field. Change the Inputfield type to CropImage. Set the maximum file uploads to 1. And added this field to a template.

Now when I try and add an image to this field in the page-edit dialogue I get the error message as pictured in the attached image (in short, it says Method PageImage::getThumb does not exist...)

thumb_error_message.jpg

Am I doing something wrong here? Any thoughts on a solution?

Many thanks in advance.

b

Link to comment
Share on other sites

  • 5 weeks later...

Am I the only one who finds the naming in this module rather confusing?

In ModulesManager/on PW Site:
- it is called Thumbnails
 
Module detail page:
- after installing it, the title in Admin > Module says Images with cropping
- the class is called ProcessCropImage
- the description says Crop thumbnails
 
in Modules list its components are listed as:
- FieldType: Images with cropping
- Inputfield: Images with cropping
- Process: Image cropping tool
 
So we have about 5 different names:
Image cropping tool
CropImage (FieldtypeCropImage/InputfieldCropImage/ProcessCropImage)
Thumbnails
Images with cropping
Crop thumbnails
 
Is there a reason behind this? I feel this should be more organized.
  • Like 1
Link to comment
Share on other sites

The classnames are following the nameing conventions,

but the descriptions not all.

I would like the name Thumbnail in front of all 3 descriptions because it is known as "the Thumbnails module"! :)

Link to comment
Share on other sites

The classnames are following the nameing conventions,

but the descriptions not all.

I would like the name Thumbnail in front of all 3 descriptions because it is known as "the Thumbnails module"! :)

They still could be named FieldtypeThumbnails, InputfieldThumbnails and ProcessThumbnails ... if Thumbnails is the way to go.

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

Hi all,

is there a method to regenerate all thumbs from api (command line)?

I have to change all thumbnail setting and after that recreate thumbs with different sizes and delete the oldest.

Probably a double request but I cannot find the right post/thread.

Thanks

Link to comment
Share on other sites

I have just tested and merged pull request from horst and owzim that adds support for PageImageManipulator in thumbnails cropping view. This is great addition!

If you don't have PIM installed, it will work just as usual, so updating should be safe. If you do use PIM, make sure you are running latest version, since earlier throws error when using cropping tool.

Thanks for your work on this horst and owzim!

post-18-0-08896300-1378485336_thumb.png

PS: It maintains the settings and also coordinates, but coordinates aren't active when re-cropping. It shows preview of different part of image, but when proceeding still (rightly) crops the old part. Probably the cropping tool JS needs some refresh...?

  • Like 3
Link to comment
Share on other sites

Hi all,

is there a method to regenerate all thumbs from api (command line)?

I have to change all thumbnail setting and after that recreate thumbs with different sizes and delete the oldest.

Probably a double request but I cannot find the right post/thread.

Thanks

Unfortunately there ain't API for that. Should be possible with PHP though. Anyone done cleaning script for that?

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