Jump to content

Release: Thumbnails


apeisa

Recommended Posts

Hi Doolak, I haven't tried retrieving them yet because I was getting the error message on upload. I looked in the database table for thumbnails and there was no reference to them, even though they were getting uploaded, resized, and renamed ok.

Thanks 

Mike

Link to comment
Share on other sites

Thanks for this module!

Works fine, but is there any way to

have the preview images sized like

inside the default images field?

Some previews just turn gigantic ;)

One more question: Are there any API differences between default image field and this one?

I think in that case I would just replace the default one instead of running two image filds..

post-1110-0-89056100-1363354522_thumb.pn

Edited by FvG
Link to comment
Share on other sites

Brilliant plugin! 

Works great locally but online i get the following error. Seams like something is missing on my server?

Anyone have a clue?

Fatal error: Call to undefined method InputfieldImage::renderitem() in /var/www/hobbyimage.com/site/modules/InputfieldCropImage/InputfieldCropImage.module on line 29

Short info of my online server

PHP Version 5.2.4-2ubuntu5.10

Client API version    5.0.51a
GD Support    enabled
GD Version    2.0 or higher
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.3.5
 
 
Locally
PHP Version 5.3.5
Client API version    5.5.9
GD Support    enabled
GD Version    bundled (2.0.34 compatible)
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.4.4
 
Could it be something with the gd2 lib? Im running pw 2.2
  • Like 1
Link to comment
Share on other sites

Actually that error message does make sense. Though this might be something that wouldn't behave the same way in all PHP versions. But it's something that should be changed in InputfieldCropImage either way. Starting on line 27 of InputfieldCropImage.module, can you change this:

protected function renderItem($pagefile, $id, $n) {

  $out = parent::renderItem($pagefile, $id, $n);

with this:

protected function ___renderItem($pagefile, $id, $n) {

  $out = parent::___renderItem($pagefile, $id, $n);

Basically, prepend three underscores "___" to the renderItem definition and call. 

  • Like 1
Link to comment
Share on other sites

Thank you Ryan! 

Now it works online just as on my local mamp server.

(And when i updated the code locally to Ryans it still works locally. )

There is my confirm Apeisa. 

Apeisa and co workers, thanks again this sweet plugin is perfect for me and my coming projects.

Donation will arrive as I get paid.

/M

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Not sure whether it is something related to my system, but the last two sites I have tried to install this on (using the modules manager), it has failed and prevented the site from loading at all. All I have to do to fix it is delete the module folder from the server, reload the PW admin and then install it again and everything is fine. Sorry I don't have any useful debugging info, but if someone else has this problem as well, it might be worth investigating.

Link to comment
Share on other sites

@adrian, I'm sorry for this I just tested and installed Thumbnails using MudolesManager (:)) and it workd fine first time. Is it working second time with ModulesManager or do you install it manually?

Not sure what was causing it, maybe it was a corrupted download or zip extract. Can you reproduce it everytime on different servers? Is it only this modules or also others? ModulesManager is trying to show some errors if something didn't work, but sure not all scenarios. If you can get more information by enabling debug mode or see if any errors got logged? Or try to see if there's a difference in the files from the one you would install manually when it's crashing. I also happend to have some problems with permissions on servers that are not configured well on a cheap hosting. 

Link to comment
Share on other sites

Soma - sorry, been absolutely swamped. I reinstalled with the ModulesManager. Weird thing is that this is the second time it has happened, on the same server. It is the only module that has caused me any installation problems. Next time I go to install it I'll be sure to do some debugging. The server is one I manage myself and I think it is configured ok :)

Link to comment
Share on other sites

A couple of hopefully quick questions.

I can't seem to find a way to use the "Select Image" feature within a text area to select one of the cropped images. It only seems to load up the original uncropped images. Is this possible?

Also, is it possible to not do any cropping by default, but rather only if the user chooses to. I want them to be able to choose to crop just one of the images in a multi images field then grab that one (or the first one of the images) that has a cropped version. Make sense?

Thanks! 

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.

Link to comment
Share on other sites

@marty, just read this and I thought you don't use images in RTE? :P

However I think with my ImagesManager it would be easily possible to add a image from thumbnails...

{image=1023, thumbnail=small}

Link to comment
Share on other sites

Hey Marty,

Great idea on adding the cropped image to an image field. I might take a look at the module and tweak it to do that - I expect it should be fairly straightforward.

Hey Soma - I personally like the concept of your imagesManager, but my users are very non-tech, so I don't know how it would fly with them. I am also not a fan of allowing/encouraging users to insert images into a RTE if the site structure can be standardized, but it isn't always possible unfortunately.

Link to comment
Share on other sites

Ok, I made a very simple hack to the thumbnails module. Inside public function ___executeSave() within the ProcessCropImage.module I added the following lines just before the timestamp comment.

		if(!$page->$prefix) {
			$f = new Field();
			$f->type = $this->modules->get("FieldtypeImage");
			$f->name = $prefix;
			$f->label = ucwords(str_replace('_', ' ', $prefix));
			$f->save();

			$page->template->fields->add($prefix);
  			$page->template->fields->save();
		}
		$page->$prefix->deleteAll();
		$page->$prefix->add($targetPath);
		$page->save($prefix);

Firstly it checks for the presence of a field named the same as the crops name. So, if you set up your crop as: thumbnail,100,100 then it will look for a field name 'thumbnail'. If it's not found, it creates it and adds it to the current page's template. I would like to be able to set the field visibility and Maximum files allowed settings, but haven't figure that out yet.

Then it takes the cropped image and adds it to that field.

Only minor inconvenience is that the image won't appear in the thumbnails field until the user saves the page. Not sure if there is any way around that - I feel like there should be a way to hook into the ajax image uploader to refresh the field, but haven't investigated yet.

Antti, is this something you'd consider adding (maybe as a configurable option), or do you think my need is too specific?

  • Like 2
Link to comment
Share on other sites

Thanks, I'll set up a pull request shortly. But for the sake of finalizing the code here too, here is the revised version which does a few more checks and other things. Hopefully my logic is sound.

Also, just in case someone is interested. I am using this along with my, not yet released, PDFImageCreator module(http://processwire.com/talk/topic/3304-pdf-image-generator/). The module generates images from all the pages of a uploaded PDFs. Then I use this addition to the Thumbnails module to allow admin users to crop out a carousel/slider image from the PDF image to be used on the site's homepage.

if(!$page->$prefix) {

	if(!wire('fields')->get($prefix)){ //If field with name matching the crop name doesn't exist, create it
		$f = new Field(); // create new field object
		$f->type = $this->modules->get("FieldtypeImage"); // get a field type
		$f->name = $prefix;
		$f->label = ucwords(str_replace('_', ' ', $prefix));
		$f->description = 'This field stores user cropped images from other image fields on this page. To see new additions, you need to save this page.';
		$f->save(); // save the field
	}

        //Add field to the page's template
        //This is separated out in case the field already exists, but is not in this template
	$page->template->fields->add($prefix); 
	$page->template->fields->save();
}

$page->$prefix->add($targetPath); //Add the image to the field
$page->save($prefix);

//If the developer sets the maxFiles value for the field to '1' and there is already an image in there, then delete the first one after adding the new one.
//This seems to be necessary because the maxFiles = 1 setting doesn't limit addition of extra images via the API
if(wire('fields')->get($prefix)->maxFiles==1 && count($page->$prefix) > 1){
	$page->$prefix->delete($page->$prefix->first());
	$page->save($prefix);
}
  • Like 1
Link to comment
Share on other sites

I mean this: you guys amaze me.

And the risk of making a dog's breakfast of this I'm also wondering if the image field that thumbnails get saved to could be configurable. There might be some instances where it might be preferable to have them separate. Just thinking out loud really.

Cheers

Marty

Link to comment
Share on other sites

Hey Marty,

I think that could be a good idea too. Having images saved to a custom image field would allow a lot of flexibility, especially for allowing admin users to insert images into a RTE on another page.

It seems there has been significant discussion already on the config setup, ie. largethumb,200,200,basic-page,home

I fear that maybe we need to go the JSON route (as suggested earlier), if we start adding any more options.

Anyone have any more recent thoughts on this?

Link to comment
Share on other sites

Hi everyone, i ran into a problem after installing cropImages. Everything seems to work fine up to the point where I actually crop. The crop ui pops up and I drag a rectangle and click "Crop and go". But the cropped image isn't the one I selected but seems to come from the center of the original image. I'm on php54 and GD2 is installed. Any ideas?

I'm relatively new to PW, so I might be missing something. Any help is appreciated.

Update:

I think it might be a permission problem. When I manually delete the file and then do the cropping, everything works fine.

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