image cropper issue

Rick's Avatar


11 Feb, 2012 08:41 AM

With "thumbnail_prototypes" set in my config.yaml, I am getting the following error when accessing the Image
Cropper panels:

Can't use string ('') as a subroutine ref while 'strict refs' in use at /mt4/plugins/ImageCropper/lib/ImageCropper/ line 253

On line 253, I found:

label => &{ $p->{label} },

which I changed to:

label => sub{ $p->{label} },

Which allowed the plugin configuration panel to open normally. However, when I tried to generate a thumbnail for an asset, I saw an extra thumbnail prototype with label "X" and max_width and max_length of zero. That was annoying, but didn't stop the plugin from functioning. For a complete "fix" I added a conditional if $p->{label} to the "push @protos" block:

`push @protos, { id => $_,

type         => 'template_set',
key          => "$ts::$_",
template_set => $ts,
blog_id      => $blog->id,
label        => sub{ $p->{label} },
max_width    => $p->{max_width},
max_height   => $p->{max_height},

} if $p->{label};`

I'm not sure of the exact cause of my problem. I noticed that the problem doesn't arise if I delete the thumbnail prototypes from my config.yaml. But I looked closely, and I couldn't find a problem with my YAML, so I kept the prototypes in and fixed the proble with the two code changes.

Do you have any advice? Is it prudent to make those two changes in the ImageCropper plugin? Please consider this patch and let me know what you decide.


  1. 1 Posted by Rick on 11 Feb, 2012 09:06 AM

    Rick's Avatar

    To be clear, changing &{ $p->{label} } to &sub $p->{label} } allowed both the ImageCropper configuration panel and the "generate thumbnails" panels to open without error. The conditional removed the unexpected x-labeled prototype that came from nowhere. Also, just adding the conditional by itself fixes the plugin.

    BTW, what is wrong with just using $p->{label} by itself without placing it in a code block? It seems to work that way.

  2. 2 Posted by Dan Wolfgang on 27 Feb, 2012 07:59 PM

    Dan Wolfgang's Avatar

    I was just working with Image Cropper (version 1.0.21) and don't see any error like you report. What version are you using?

  3. 3 Posted by Rick on 28 Feb, 2012 10:42 PM

    Rick's Avatar

    I'm sure that it was the latest version as of February 11th. Honestly, I can't even recall which website I was working on when this occurred. I likely set up some odd condition that triggered this behaviour, and doubt that I could reproduce it. I remember staring at that config.yaml so hard that if it was a goat, it'd drop over dead.

    I am just offering up this code patch proactively to perhaps make the code less brittle. I understand that you would be reluctant to fix what "ain't broke".

    While I'm still not entirely clear on the role of ampersands in referring to subroutines, I did find an interesting primer on the subject .

  4. 4 Posted by Dan Wolfgang on 02 Aug, 2012 04:48 PM

    Dan Wolfgang's Avatar

    I've just run into this problem and pushed a fix to which does two things:

    • Skips over a thumbnail prototype if it doesn't contain the required values.
    • Just print the label.

    The second one is what you were dealing with, I think, and you're right, just using $p->{label} is simpler. (better?) Executing it as a subroutine means you can specify code for the label, creating a programmatically-built label... but I haven't seen any use of that and I'm not sure it's something to encourage... so I just removed it.

  5. Dan Wolfgang closed this discussion on 02 Aug, 2012 04:48 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac