Skip to content

Commit

Permalink
adding an url() method and HTML options to thumbnail()
Browse files Browse the repository at this point in the history
  • Loading branch information
msadouni committed Sep 26, 2011
1 parent b9be1ab commit 9749689
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
26 changes: 26 additions & 0 deletions readme.md
Expand Up @@ -67,6 +67,14 @@ In the view, generate the thumbnail :
In the `$options` array you can use any valid phpThumb() option. For detailed
information on the available options, check [phpThumb()'s readme](http://phpthumb.sourceforge.net/demo/docs/phpthumb.readme.txt)

You can also pass HTML options :

echo $this->PhpThumb->thumbnail(
'img/image.jpg',
array('w' => 100, 'h' => 100, 'zc' => 1),
array('alt' => "Alternative text")
);

### MeioUpload'ed image

// for a Post with an image field containing my-post.jpg
Expand All @@ -80,3 +88,21 @@ This will also work :
echo $this->PhpThumb->thumbnail('uploads/post/image/.$post['Post']['image'], array(
'w' => 100, 'h' => 100, 'zc' => 1
));

### Image url

To get only the image url, use the `url` method :

echo $this->PhpThumb->url('img/image.jpg', array(
'w' => 100, 'h' => 100, 'zc' => 1
));

It's useful for the various Javascript gallery script, like Lightbox / Thickbox / Colorbox etc. :

echo $this->Html->link(
$this->PhpThumb->thumbnail(
'img/image.jpeg', array('w' => 100, 'h' => 100, 'zc' => 1)
),
$this->PhpThumb->url('img/image.jpeg', array('w' => 640, 'h' => 640)),
array('escape' => false)
);
22 changes: 16 additions & 6 deletions views/helpers/php_thumb.php
Expand Up @@ -122,8 +122,8 @@ public function generate($options = array()) {

return $this->get_thumb_data();
}
function thumbnail($image, $options) {

function generateThumbnail($image, $options) {
$thumbs_path = Configure::read('PhpThumb.thumbs_path');
if (empty($thumbs_path)) {
return false;
Expand Down Expand Up @@ -155,10 +155,20 @@ function thumbnail($image, $options) {
$options['src'] = WWW_ROOT . $image;
}
$finalOptions = array_merge($options, $pathOptions);
$thumbnail = $this->generate($finalOptions);
return $this->image($thumbnail['src'], array(
'width' => $thumbnail['w'], 'height' => $thumbnail['h'])
);
return $this->generate($finalOptions);
}

function url($image, $options) {
$thumbnail = $this->generateThumbnail($image, $options);
return $thumbnail['src'];
}

function thumbnail($image, $options, $htmlOptions = array()) {
$thumbnail = $this->generateThumbnail($image, $options);
return $this->image($thumbnail['src'], array_merge(
array('width' => $thumbnail['w'], 'height' => $thumbnail['h']),
$htmlOptions
));
}
}
?>

0 comments on commit 9749689

Please sign in to comment.