Drupal's image module has the option to let visitors view the original resolution of an image. However, the only way to view the original is to click on the "view original" link below the image.
This may not be what the client wants, since a more common way of presenting images on the web is to make the image clickable to the higher resolution image.
For a demo of this feature, please visit Ads of the World.
This article discusses how to do that for Drupal 4.6, 4.7 and 5.0.
For Drupal 4.6
For Drupal 4.6, the image.module has to be modified to make this possible. Here is how to do so.
In image.module, find the line that says:
function image_display(&$node, $label = 'preview', $attributes = array()) {
A few lines below that you will see this line that starts with :
$output.= theme('image', file_create_url($node->images[$label]), ...
Add the following code before it:
// *** Display original as a link from the image
if ($_GET['q'] == drupal_get_normal_path('node/' . $node->nid)) {
// We are viewing the node itself, not the gallery
if ($label != '_original') {
// We are not already in the view original mode
if ($node->images['_original']) {
// The node does have an original in the list
$pre = "<a href='" . url("node/" . $node->nid) . "?size=_original'>";
$post = '</a>';
}
}
}
$output .= $pre;
And then add the following line after it:
$output .= $post;
For Drupal 4.7 and 5.0
Things are easier in Drupal 4.7 and 5.0. You do not need to edit the image.module, but can override the way the image is displayed.
What you need to do is edit the template.php in your theme directory, and add the following function to it:
function phptemplate_image_display($node, $label = 'preview', $url = NULL, $attributes = array()) {
// *** Display original as a link from the image
if ($_GET['q'] == drupal_get_normal_path('node/' . $node->nid)) {
// We are viewing the node itself, not the gallery
if ($label != '_original') {
// We are not already in the view original mode
if ($node->images['_original']) {
// The node does have an original in the list
$pre = "<a href='" . url("node/" . $node->nid) . "?size=_original'>";
$post = '</a>';
}
}
}
$output .= $pre;
$output .= '<img src="'. check_url($url) .'" alt="'. check_plain($node->title) .'" title="'.
check_plain($node->title) .'" '. drupal_attributes($attributes) .' />';
$output .= $post;
return $output;
}
Now, if a visitor is viewing an image node, and they mouse over the image, they will get a link to the original resolution version of that image node.
Enjoy.
Comments
Visitor (not verified)
thanks!
Thu, 2007/01/11 - 18:10It was a much needed feature for image.module. Thank you!
Visitor (not verified)
I notice in your example
Thu, 2007/01/11 - 18:19I notice in your example that a link is provided even when the thumbnail /is/ the original image and there is none larger. This is a bit confusing. Also it might be an idea to remove the "view original" text link.
Khalid
Adjustments may be needed
Thu, 2007/01/11 - 21:15Yes, you need to adjust the code in this case, which is not the case we did this for.
--
2bits -- Drupal and Backdrop CMS consulting
Visitor (not verified)
Looks like this will be very
Thu, 2007/01/11 - 19:02Looks like this will be very useful - thanks!
Visitor (not verified)
Latest post to display original image
Thu, 2007/12/06 - 22:20Hi, is there a way to make the latest post display the original image by default instead of the thumbnail?
Thanks.
Visitor (not verified)
good one. one question
Wed, 2008/03/19 - 10:55good one.
one question though, what if i'd like to show the original size in a blank page cause it shows it in a node page breaking all the layout. any ideas?
thanks
Visitor (not verified)
Show in blank page
Tue, 2009/11/24 - 00:00To show your image outside of the template of your site you will want to make a php template file for the image content type that was automatically created. Something like node-image.tpl.php.
Visitor (not verified)
Thanks my friend
Tue, 2009/11/24 - 00:04I just had to do this to a drupal 4.7 site and I was glad that I found your post. I personally wrote a post on installing and using Image Assist in Drupal 6:Configuring Image Assist in Drupal 6, but my knowledge doesn't go back to 4.8 THANKS AGAIN.
Visitor (not verified)
i would know what to do to
Fri, 2010/02/19 - 13:46i would know what to do to have the same result in drupal 6.1.
Thank you
Visitor (not verified)
I would like to know how to
Sun, 2010/03/28 - 16:35I would like to know how to do it in drupal 6.x as well!
Thanks!