Hi,
Would it be possible to style a link-field to be an image-url, and output it as an image please?
I see this code which somewhat looks like doing sort of the same for other field: http://drupal.org/node/1110132
What would be the formatter code for a link-field to build a thumbnail image of it please?
Thanks a lot in advance for your reply!

Greetings, Martijn

CommentFileSizeAuthor
#5 imageurl_link.jpg141.9 KBsummit

Comments

summit’s picture

Hi,
I tried the following:

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

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

But then I got this output, and not the image in the medium style:

http://styles/medium/http/[URL TO IMAGE}

Greetings, Martijn

summit’s picture

Hi,
After reading more, off course only the url is returned, that is the purpose of the function.
Now I try to get the image itself, but until now unsuccesfull.
I tried related to: http://drupal.org/node/958726#comment-5195838

// Set the value to the desired image url and style.
$img_url = $variables['#items'][0]['url'];  // the orig image uri
$style = 'medium';  // or any other custom image style you've created via /admin/config/media/image-styles

return <img src="<?php print image_style_url($style, $img_url) ?>">

EDIT: I think I have to do something with: http://api.drupal.org/api/drupal/modules--image--image.module/function/t..., but don't know how.
But it doesn;t show the image. Can you help please?
Greetings, Martijn

summit’s picture

Hi,
I tried:

// Set the value to the desired image url and style.
$img_url = $variables['#items'][0]['url'];  // the orig image uri
$style = 'medium';  // or any other custom image style you've created via /admin/config/media/image-styles

return theme('image_style', array( 'path' => $img_url, 'style_name' => $style));

I got some result, but still I see in the code this then as url:

http://styles/medium/http/[WWW URL TO IMAGE]

EDIT: I read the following..path: The path of the image file relative to the Drupal files directory. This function does not work with images outside the files directory nor with remotely hosted images.
EDIT2: May be something like: http://drupal.org/node/1110132#comment-4837998
How can I get this remotely hosted image to show please?

Can you help please?
Greetings, Martijn

summit’s picture

Hi,
I got something working with:

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

I misuse the title field of my linkfield to get to the real url of the image instead of the image-url.

What I really want to integrate: the image styles like thumbnail, so I have this admin on one place.
Do you know how to do that may be?
Greetings, Martijn

summit’s picture

Title: Image formatter for link field » Error in src in Image formatter for link field
Category: support » bug
StatusFileSize
new141.9 KB

Hi, I have a problem with urls like:

http://wintersport.sunweb.nl/utilpages/getimage.ashx?width=264&height=176&file=Images/Web1/900000/58000/958964-Web1.jpg

See attached image for the correct #items url array.
But when I try this as a custom formatter the src is "http://wintersport.sunweb.nl/utilpages/getimage.ashx" instead of the whole url.
See underneath the sourcecode output after using the custom formatter from http://drupal.org/node/1397700#comment-5443478

<a title="Hotel Alpina" href="http://wintersport.sunweb.nl/reizen/?tt=2830_0_93510_&amp;r=http%3A%2F%2Fwintersport.sunweb.nl%2Foostenrijk%2Folympiaregion_seefeld%2Fseefeld%2Fhotel_alpina.htm"><img width="200" height="150" alt="Hotel Alpina" src="http://wintersport.sunweb.nl/utilpages/getimage.ashx" /></a><div>Hotel Alpina</div>

I think somewhere the formatter goes wrong with the query sting like "?width=264&height=176&file=Images/Web1/900000/58000/958964-Web1.jpg" in the url.
Hopefully you can help?
Greetings,
Martijn

summit’s picture

Hi,
It was a link module problem, see this issue-patch http://drupal.org/node/1309658#comment-5168960

greetings,
Martijn

summit’s picture

Title: Error in src in Image formatter for link field » [SOLVED} Error in src in Image formatter for link field
Status: Active » Fixed

Status: Fixed » Closed (fixed)

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