Drupal Module : image_style_argument


Drupal has a very powerful image manipulation UI, so why write code when we can easily use that forany purpose?! The problem is we can't! The reason is image manipulation UI only accepts one argument which is the source image. All other parameters and options are static. For example if you want to put the source image behind a frame you can, but if you want to dynamically change frame's image you either have to make new preset/style for each different frame or write a custom special action.

Another example is rendering texts dynamically, you can pass any text you want to the image style and have it rendered without writing any custom action

I've written a new module image_style_argument  (Latest version is also attached) to address this limitation by letting you pass any argument to image module, parameters pass via query string and using them you can override any style parameters on the fly.

Although this solution works but it's only a workaround and we need proper implementation , i've opened-up a new issue for this feature, join in if you're interested : http://drupal.org/node/1715300

From Module's README.txt

//Use the following code to see the style's parameters
  $style = image_style_load('style_name');
//Use the following code override style parameters and generate image url (effects index numbers are actually their ids , so they will not change when you add/remove effects or even when you rearrange them) : 
  $style_override = array('effects' => array(
    9 => array ( //Overlay (watermark)
	  'data' => array (
	    'path' => 'public://my_frame.jpg'
  image_style_argument_url('style_name', 'public://myimage.jpg', $style_override);
//You can also use theme_image_style_argument() as an alternative to theme_image_style()
  theme_image_style_argument(array('data') => $style_override)
//By default it does not support image caching since Drupal bypasses caching whenever url has query string, to fix this problem and also shortening the url length you can define 
//your own special logic simply by implementing two hooks.
//- mymodule_image_style_argument_url_override(&$uri, &$url, &$style_name, &$path, &$data)
//- mymodule_image_style_argument_override(&$image_uri, &$derivative_uri, &$style, &$scheme)
image_style_argument.zip26.5 KB
Your rating: None Average: 4 (2 votes)