What was easy with Drupal 6 and Views is now kinda tricky in Drupal 7...

I would like to output the path to an imagestyle rendition of a file (EG: /files/styles/stylename/filename) that I could use in a javascript (EG: 'url' : '/files/styles/thumbnail/filename.jpg').

Sadly I have only minimal PHP skills ... if anyone could offer a solution (for Drupal 7), it would be greatly appreciated.

I initially raised an issue under Views and maintainer Dereline suggested CF was probably the solution.

Comments

deciphered’s picture

Status: Active » Fixed

Sorry for taking so long, but below is the code you want.

Single value formatter:

// Set this value to the desire style.
$style = "thumbnail";

// Leave everything below as is.
return image_style_url($style, $variables['#item']['uri']);

Multiple values formatter:

// Set this value to the desire style.
$style = "thumbnail";

// Leave everything below as is.
$output = '';
foreach ($variables['#items'] as $item) {
  $output .= image_style_url($style, $item['uri']);
}
return $output;
barwonhack’s picture

You are a legend!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Jerome F’s picture

thank you - subscribing to keep it in mind

TimelessDomain’s picture

This is my 1st custom written php snippet. If you can improve upon it post.

This takes the image url & converts it into an embedded image with colorbox popup. I didn't know how to mod this so it works for multiple images,. If its possible to only have the first image show embedded & then the rest in colorbox, that would be great! Also - could someone could post how to link this to the node? thanks

// Set this value to the desire style.
$style = "medium";
$styletwo = "original";

// Leave everything below as is.
$imglink= image_style_url($style, $variables['#item']['uri']);
$imglinktwo= image_style_url($styletwo, $variables['#item']['uri']);

$output = '<a href="' . $imglinktwo . '" class="colorbox-load"><img src="' . $imglink . " " . '"></a>';
return $output;
Jerome F’s picture

@TimelessDomain you could also just just use the url formatter and take care of the rest in views with fields and rewrite rules. I tried to find a solution for the multiple images, but apparently colorbox needs to have all the actual images on the page to make the popup, and I couldn't find any other workaround, appart from using views slideshow in a colorbox trigger field: http://drupal.org/node/1161274#comment-4485714

deciphered’s picture

@TimelessDomain

Quick coding standards rewrite:

// Set this value to the desire style.
$style = "medium";
$styletwo = "original";

// Leave everything below as is.
$imglink= theme('image_style', array('style_name' => $style, 'path' => $variables['#item']['uri']));
$imglinktwo= image_style_url($styletwo, $variables['#item']['uri']);

$output = l($imglink, $imglinktwo, array('html' => TRUE, 'attributes' => array('class' => 'colorbox-load')));
return $output;

Note: Untested, but should be right.

Lithops’s picture

Hi,

I try this with 7.x-2.0-beta2 :

// Set this value to the desire style.
$style = "thumbnail";

// Leave everything below as is.
return image_style_url($style, $variables['#item']['uri']);

I have the right path, but without the filename at the end.

a little help?

Sorry for my english... ;)

deciphered’s picture

The structure of the $variables object has changes in 7.x-2.x, it would now be: $variables['#items'][0]['uri']

sachbearbeiter’s picture

subscribe

julien.reulos’s picture

I also work with the 7.x-2.x-dev version and a multiple link_field field type.
The code that is working for me (in this particular case, to render image links as thumbnails) is:

$output = '';
foreach ($variables['#items'] as $item) {
  $output .= '<a title="' . $item['title'] . '" href="' . $item['url'] . '"><img width="100" height="75" alt="' . $item['title'] . '" src="' . $item['url'] . '" /></a><div>' . $item['title'] . '</div>';
}
return $output;	
barwonhack’s picture

Priority: Normal » Major
Status: Closed (fixed) » Active

#8 and #9 no longer seem to work in Drupal 7.21

Any suggestions?

summit’s picture

Hi, is #11 still valid? is it to be used with the link module?
EDIT I did a time back this: https://drupal.org/node/1397700#comment-5443478

Greetings, Martijn

deciphered’s picture

Issue summary: View changes
Status: Active » Fixed

Most likely the reason they stopped working is due to the addition of itok for DDOS protection.

See https://api.drupal.org/comment/49773#comment-49773 for workaround.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.