How to use it properly

How to use it properly

Shortcode or template tag?

There are two possible use cases: Either place the shortcode inside your post content, or use a template tag.

Shortcode

Place [dynamic_image] in your content. The shortcode has four arguments:

Template Tag

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

Inside the loop:

1 echo dynamic_image_resize( array(
2 	'src'     => array_shift( wp_get_attachment_image_src(
3 		get_post_thumbnail_id( get_the_ID() ),
4 		"Full"
5 	) ),
6 	'width'   => 60,
7 	'height'  => 100,
8 	'classes' => 'thumb',
9 ) );

Outside the loop with a path to an attachment:

1 // The args need to be an array
2 echo dynamic_image_resize( array(
3 	// The full path to the image in your uploads folder
4 	'src'     => 'http://example.com/wp-content/uploads/2012/03/some_image.png',
5 
6 	'width'   => 60,
7 	'height'  => 100,
8 	'classes' => 'some classes to align and style the image',
9 ) );

Outside the loop with an attachment ID:

1 // The args need to be an array
2 echo dynamic_image_resize( array(
3 	// the ID
4 	'src'     => 6,
5 
6 	'width'   => 60,
7 	'height'  => 100,
8 	'classes' => 'some classes to align and style the image',
9 ) );