Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm having trouble using the "Dynamic-Image-Resize" plugin by "Kaiser Franz Josef". In my template I'm adding following code:

$imgsrc = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "Full");
$image_path = $imgsrc[0];

dynamic_image_resize( array(
    'src'     => $image_path    
    ,'width'   => 60
    ,'height'  => 100
    ,'classes' => 'thumb'
) );

It just outputs nothing, neither it give any error. I have made sure that the image path is correct. How can I find out where is the problem?

If I var_dump the output of the above function, I get following:

object(oxoDynamicImageResize)#507 (1) { ["atts"]=> array(4) { ["src"]=> string(55) "http://localhost:81/wp/wp-content/uploads/2013/02/1.jpg" ["width"]=> int(60) ["height"]=> int(100) ["classes"]=> string(5) "thumb" } } 

I will highly appreciate any help.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Ask the right guy

Which you just did, so... here's your answer from the developer. :)

What does the right output tell us?

First of all, the public dynamic_image_resize() API function is just a wrapper for the singleton itself. When you take a closer look at the class, you'll notice a __toString() method, which is the magical method that returns the output.

As you've seen from your var_dump(), you get back the exact object (the class name indicates that), but not the string. So the __toString() method didn't trigger and therefore doesn't call the output. It just called the __construct() method with your attributes, so you see the exact same thing set as the class properties, that you defined when calling the class.

How to "fix" something that isn't broken?

The class, as stated previously, uses the __toString() method. This method - as most magical PHP methods - only trigger under a certain condition. In this case, when you echo the output.

So your solution would simply be to echo dynamic_image_resize(). Here's it written quickly (not tested).

echo dynamic_image_resize( array(
     'src'     => array_shift( wp_get_attachment_image_src( 
         get_post_thumbnail_id( get_the_ID() )
        ,"Full"
     ) )
    ,'width'   => 60
    ,'height'  => 100
    ,'classes' => 'thumb'
) );
share|improve this answer
1  
Thank you so very much for the great work and the detailed answer. –  jay Feb 28 '13 at 10:32

You can try the shortcode version:

$imgsrc = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), "Full");
$src=$imgsrc[0];
$width=60;
$height=100;
$sc=sprintf('[dynamic_image src="%s" width="%d" height="%d" ]',$src,$width,$height);
echo do_shortcode($sc);
share|improve this answer
    
No reason to echo the shortcode :) –  kaiser Feb 26 '13 at 14:17
1  
ok thanks, I was just writing a comment to tell him to wait for your answer ;-) –  birgire Feb 26 '13 at 14:19
    
Thanks for offering support and help for the plugin. Appreciated :) –  kaiser Feb 26 '13 at 14:21
1  
thanks for a great plugin ;-) –  birgire Feb 26 '13 at 14:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.