Forum for discussing general topics related to Couch.
5 posts Page 1 of 1
Developing a blog site for a client that wants to be able to add multiple images to each blog post - differing locations, sizes and number of them in each blog post.

I've made some short codes for them so they can do this quite easily without needing to do formatting as the short code does that all for them of course.

But I can't seem to find a nice way to automate the image resizing for this.

They're uploading images which can be sometimes quite large (often 6MB+) which then need to be resized down to a reasonable size for display in the page (size varies image to image), and display when zoomed (FancyBox).

Is there a nice way to do this?

Can I use timthumb directly in my shortcode function perhaps?

TY!
We can use Couch tags within shortcodes (e.g. as in the '6. Obfuscate email' example in docs - http://docs.couchcms.com/miscellaneous/ ... shortcodes).

I think you can use that technique to embed <cms:thumbnail> tag (http://docs.couchcms.com/tags-reference/thumbnail.html) and that should take care of doing the resizing for you.

Hope it helps.
Do share the shortcode with us if it does :)
It works!

At the moment you have to put in the URL as a param but I'll code it up to extract the URL out of the $content when someone pastes an image into the shortcode also as a simpler alternative for my client.

class 'fbx' is the class I've made that gets FancyBox assigned.

Image displayed has been created at shortcode requested size of 300px wide.

Here's how to use it:

Code: Select all
[autoim width="300" caption="this is my caption" url="https://mysite/uploads/myimagehere.jpg"]


Here's the code:

Code: Select all
$FUNCS->register_shortcode( 'autoim', 'autoim_handler' );

   function autoim_handler( $params, $content=null ){
      global $FUNCS;

     $para = $FUNCS->get_named_vars(array(
             'width'  => '',
             'caption' => '',
             'url' => ''), $params);

      // Create Couch script..
      $html = "<a href='".$para['url']."' class='fbx' title='".$para['caption']."'><img src='<cms:thumbnail src='".$para['url']."' width='".$para['width']."' />' alt=\"".$para['caption']."\"></a>";

      // Pass on the code to Couch for execution using the 'embed' function
      return $FUNCS->embed( $html, $is_code=1 );
   }


Thank you!
Thanks for sharing :)
Here's how to test for and extract out the URL of the image if it's added visually instead of by param:

Code: Select all
   
$FUNCS->register_shortcode( 'autoim', 'autoim_handler' );

function autoim_handler( $params, $content=null ){
      global $FUNCS;

      $para = $FUNCS->get_named_vars(array(
             'width'  => '',
             'caption' => '',
             'url' => ''), $params);

     if (strlen($para['url']) == 0)
     {
        // perhaps they sent the url in the content as an image
        // <img alt="" src="https://www.mysite.com/uploads/images/1.jpg" style="width: 100px; height: 127px;" />
        if (preg_match("/\<img.+src=\"(.+?\.)(jpg|png|tif|tiff|jpeg)\"/", $content, $matches))
        {
           $para['url'] = $matches[1] . $matches[2];
        }
     }

      // Create Couch script..
      $html = "<a href='".$para['url']."' class='fbx' title='".$para['caption']."'><img src='<cms:thumbnail src='".$para['url']."' width='".$para['width']."' />' alt=\"".$para['caption']."\"></a>";

      // Pass on the code to Couch for execution using the 'embed' function
      return $FUNCS->embed( $html, $is_code=1 );
   }
5 posts Page 1 of 1