Last updated 30 June 2016. Created on 21 February 2011.
Edited by puravida, arsirc, geobaev, rwohleb. Log in to edit this page.

The ShrinkTheWeb module at http://drupal.org/project/shrinktheweb allows caching and display of thumbnail images generated by the ShrinkTheWeb service at http://www.shrinktheweb.com/.

Installation

  1. Register at http://www.shrinktheweb.com/user/register .
  2. Upload the module files on your site from http://drupal.org/project/shrinktheweb.
  3. Enable the ShrinkTheWeb module from admin/modules, section "Other".

Configuration

  1. Browse to your profile page at http://www.shrinktheweb.com/ and get the Access key and Secret keys for your profile.
  2. Browse to admin/config/media/shrinktheweb.
  3. Copy the Access key and the Secret key in the text fields.
  4. Configure the thumbnails folder where the cached images will be stored.
  5. You could configure the number of days the cached images are kept unchanged.
  6. You could configure additional ShrinkTheWeb API request parameters such as "Specific page captures", "Custom size captures" and others. Please note that some of the features only become available once you have upgraded to use them and save the settings page.

You could find more information by reading about How to use Website Screenshots.

Usage

Using Field Formatters

Starting with version 7.x-1.2, there is field formatter support for the Link module. You'll find the new formatters listed as format options on the 'Manage display' tab for all of your link fields when both modules are installed. For more details, read about content types and fields and how fields are displayed.

Sample usage for Drupal 8:

Using PHP code is not "the Drupal way", so we provide field formatters for intended usage. However, we provide PHP options to extend functionality for those who want it.

theme() function is no longer available in Drupal8. Use drupal_render() by passing a render array with a #theme key in your code instead:

Basic PHP Example (uses global settings)

<?php 
$url = 'shrinktheweb.com';
$foo = array(
'#theme' => 'shrinktheweb_image',
'#url' => $url,
);
echo drupal_render($foo);
?>

Advanced PHP Example

<?php
$url = 'bing.com';
$foo = array(
  '#theme' => 'shrinktheweb_image',
  '#url' => $url,
  '#custom_width' => 600,
  '#full_length' => true,
  '#max_height' => 320,
  '#native_resolution' => 1020,
  '#widescreen_resolution_y' => 760,
  '#delay' => 5,
  '#quality' => 90
);
echo drupal_render($foo);
?>

NOTE: In the basic PHP example or when using field formatters, the requests use the global settings from the ShrinkTheWeb Drupal admin area. Changes to the size, length, or browser resolution (viewport) affect ALL occurrences of screenshots in your Drupal installation. With the advanced PHP example, each individual array can be customized for a specific request that is different from global settings.

Legend of Optional Parameters

  • url: enter any URL. If you do not have the "Inside Pages" upgrade, the screenshot will be of the homepage only
  • custom_width: enter custom width
  • full_length: enter true|false for full-length screenshots
  • max_height: height to crop the image
  • native_resolution: browser resolution or viewport width
  • widescreen_resolution_y: browser resolution or viewport height
  • *delay: enter number of seconds to delay, AFTER page load
  • *quality: enter quality (1 to 100)

*Available to all accounts for Free

Sample usage for Drupal 7:

Use a field formatter or call the URL preview theme functions directly.

7.x-1.1 and earlier:

<?php
$url = 'http://shrinktheweb.com';
echo theme_shrinktheweb_image($url);
?>

NOTE: It is now considered "bad practice" to use the theme() function in Drupal 7 also. Please consider using the instructions for Drupal 8 above.

7.x-1.2 and later:

<?php
$url = 'http://shrinktheweb.com';
theme('shrinktheweb_image', array('url' => $url));
?>

Sample usage for Drupal 6:

The ShrinkTheWeb module's functionality should be used in custom php files such as modules or theme related functionality. This functionality could be included in Drupal block definitions or Drupal custom pages when the format of the content is set to PHP.

<?php
$url = 'http://shrinktheweb.com';
echo theme("shrinktheweb_image", $url);
?>

Please note that in most cases, the thumbnail image won't be immediately available, especially an image which is generated from an internal page. In this case, no image is displayed unless the function "theme_shrinktheweb_image" is predefined by the themer/developer. The image will be displayed once it was generated by the ShrinkTheWeb service, successfully retrieved and cached locally.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

blogook’s picture

I get an error when fetching

ACCESS DENIED: Upgrade to use this feature

how to use your module with free account at STW?

and in addition, how do i show the images related to the fetched link in my own way?

puravida’s picture

This is a really late reply, as we just learned that the developer has not maintained this module/guide for quite some time. However, I wanted to reply for the benefit of others that may see these comments.

All accounts are "Free" by default and this module will work with our free service. However, this module supports "Inside Pages", "Full-Length", and "Native Resolution" PRO features (and the Widescreen feature, which requires PRO features) BUT it does not incorporate the "ShrinkTheWeb Account API" to tell the module which upgrades you have and hide ones you don't. So, if you try to use PRO features you do not subscribe to, then they will not work and you will get the "Upgrade" message.

At some point, we will update this module and add more "intelligence" to the configuration area.

Cheers,

Brandon

puravida’s picture

Update: Now that we have ported the D7 module to D8, it is clear that "Account API" support was added to the D7 version by the original developer and that support is now also in the D8 version. The original poster, above, must have been using the D6 version, which I assume did not support the "Account API". We will verify this as we make updates and improvements to the older modules --now that ShrinkTheWeb has assumed responsibility for maintaining these modules for the Drupal community.