getdave / wp-intervention

On-demand image manipulation for WordPress via the Intervention Library.
26 stars 7 forks source link

Can't use anonymous functions inside arrays #3

Closed barisunver closed 7 years ago

barisunver commented 7 years ago

Hi. I can't seem to make this work:

$intervention_args = array(
    'resize' => array( 300, 220 ),
    'blur' => 20,
    'text' => array(
        'bla bla',
        50,
        50,
        function( $font ) {
            $font->color( '#FFFFFF' );
        }
    ),
    'rotate' => -90
);

$img_src = wp_intervention( $post_image, $intervention_args );

Everything works fine except the function inside the array of the 'text' argument. It generates the following error:

Catchable fatal error: Object of class Closure could not be converted to string in /home/asd/public_html/site/wp-content/plugins/wp-intervention-develop/src/intervention-wrapper.php on line 167

When I remove the function, everything including the 'text' argument works properly. What am I missing here?

barisunver commented 7 years ago

Okay, at least I found out that this issue is about naming the cached files. When I replaced intervention-wrapper.php#L133:

$new_filename = $file_pathinfo['filename'] . '-' . hash('md5', $this->r_implode( $args, '-') ) . $ext;

...with this:

$new_filename = $file_pathinfo['filename'] . $ext;

...I managed to generate the image with the font settings. I don't really care about the cached image (because I save the image elsewhere afterwards), so my problem's solved but the issue remains.

getdave commented 7 years ago

Hi

Thanks v much. Glad to see youre using the plugin.

Someone else on my team pointed this out. Will add hotfix for this soon.

Is there any project online i can go to to see the results of your work? Would be good to see the plugin in action.

All the best

barisunver commented 7 years ago

Hi Dave,

Due to a limitation of Intervention Image (can't set boundries for text, so a longer text exceeds the limits of the image while still being single-line) I had to stop using Intervention Image (and naturally wp-intervention) and switch to another GD wrapper called "PHP Image": https://github.com/kus/php-image

Yet that didn't solve my problem either :( I can now use a "textBox" to make a long text multiline, but "centering" that multiline text centers the textBox but not the text within it.

In short, I can't fit a long text as multiline and center it horizontally & vertically.

getdave commented 7 years ago

Ok no worries.

I think this pull request fixes the issue youve reported

https://github.com/getdave/wp-intervention/pull/2#issuecomment-286253800