MTEmbedImage

Another day, another plugin. This one lets you manipulate images. You can gather size, height, weight information from them and you can even resize them for whatever purpose you'd like. Nifty, eh?

Availability

You can download this plugin here: mtembedimage-1_21.zip

Requirements

The following are requirements for using this plugin:

Installation

To install, place the 'embedimage.pl' file in your Movable Type 'plugins' directory. The 'embedimage.pm' file should be placed in a 'bradchoate' subdirectory underneath your Movable Type 'extlib' directory. Your installation should look like this:

  • (mt home)/plugins/embedimage.pl
  • (mt home)/extlib/bradchoate/embedimage.pm

Refer to the Movable Type documentation for more information regarding plugins.

Description

This plugin allows you to place an image in your template. Well, it does a little more than that.

Tags made available through this plugin:

  • <MTEmbedImage>: Container tag for image file manipulation.
  • <MTEmbedImageHeight>: Provides the height of the given image in pixels.
  • <MTEmbedImageWidth>: Provides the width of the given image in pixels.
  • <MTEmbedImageScaleHeight>: Provides the scaled height of the given image in pixels.
  • <MTEmbedImageScaleWidth>: Provides the scaled width of the given image in pixels.
  • <MTEmbedImageSize>: Provides the size of the given image.
  • <MTEmbedImageFilename>: Provides the filename of the given image.
  • <MTEmbedImageFullFilename>: Provides the full file path + name of the given image.
  • <MTEmbedImageThumbHeight>: Provides the thumbnail image height.
  • <MTEmbedImageThumbWidth>: Provides the thumbnail image width.
  • <MTEmbedImageThumbSize>: Provides the size of the thumbnail image.
  • <MTEmbedImageThumbFilename>: Provides the filename of the thumbnail image.
  • <MTEmbedImageThumbFullFilename>: Provides the full file path + name of the thumbnail image.

<MTEmbedImage>

Tag attributes available:

  • basename: Defines the prefix of the image you want to embed. If you specify a file without an extension, EmbedImage will hunt for that file with a '.gif', '.jpg' or '.jpeg' extension (in that order).
  • thumbsuffix: Defines the suffix to use for creating a thumbnail version of the image. This is really only useful if the 'height' or 'width' attributes are used as well. MT must have write access to the directory where your original image is stored in order to create the thumbnail image.
  • height: Allows you to specify an alternate height for the image. If width is unspecified, the width will be set proportionate to the height you've given.
  • width: Allows you to specify an alterate width for the image. If height is unspecified, the height will be set proportionate to the width you've given.
  • fit: You can specify either 'crop', 'scale' or 'fit' (default is 'scale'). This option is for creating scaled thumbnails only.
  • default: An expression (which can use embedded MT tags, escaped with [ and ] instead of < and >) that is returned in case the image could not be found.

This plugin is designed to give you more control over your images. With the EmbedImage tag you can pull your image's height, width, size information and use it to populate your template.

The other benefit to this tag is it allows you to create thumbnail variations of your image files very easily. Lets say you want to have a fixed 40-pixel wide version of your images within your templates. Well, you can do that with the example provided below. The EmbedImage tag will take care of the creation of the thumbnail and will update it when it sees it needs to.

Here's an overview of this tag in the form of a demonstration:

  <MTEmbedImage basename="images/[MTEntryID]"
    height="40" thumbsuffix="-40">
    <a href="<MTEntryLink>">
      <img src="<MTEmbedImageThumbFilename>"
        width="<MTEmbedImageThumbWidth>"
        height="<MTEmbedImageThumbHeight>"
        alt="<MTEmbedImageThumbSize
               measure="k">k" hspace="5"
        border="0" />
    </a>
  </MTEmbedImage>

The 'thumbsuffix' attribute causes this tag to create or retrieve a thumbnail version of the image. The height attribute forces the height of the thumbnail to 40 pixels. Since width is not specified, width is scaled proportionately to the specified height. If the thumbnail file already exists, it is simply retrieved.

If you just want to provide a scaled down version of your full-size image without creating a thumbnail, just leave off the 'thumbsuffix' attribute. That will scale the dimensions, setting the EmbedImageScaleWidth and EmbedImageScaleHeight tags.

<MTEmbedImageHeight>

Returns the original height of the image in pixels.

<MTEmbedImageWidth>

Returns the original width of the image in pixels.

<MTEmbedImageScaleHeight>

Returns the scaled height of the image in pixels.

<MTEmbedImageScaleWidth>

Returns the scaled width of the image in pixels.

<MTEmbedImageSize>

Returns the original file size of the image in bytes or kilobytes.

Tag attributes available:

  • measure: specify 'k' for returning the filesize measurement in kilobytes.

<MTEmbedImageFilename>

Returns the filename of the image.

<MTEmbedImageFullFilename>

Returns the full path and filename of the image.

<MTEmbedImageThumbHeight>

Returns the height of the thumbnail image in pixels.

<MTEmbedImageThumbWidth>

Returns the width of the thumbnail image in pixels.

<MTEmbedImageThumbSize>

Returns the file size of the thumbnail image in bytes of kilobytes.

Tag attributes available:

  • measure: specify 'k' for returning the filesize measurement in kilobytes.

<MTEmbedImageThumbFilename>

Returns the filename of the thumbnail image.

<MTEmbedImageThumbFullFilename>

Returns the full path and filename of the thumbnail image.

Support

If you have any questions or need assistance with this plugin, please add your questions and/or comments using the form below.

License

Released under the MIT License.

Changelog

  • 1.21: Corrected closure tags for embedded expressions.
  • 1.2 - Integrated contributed code from Andrew Yoder <ayoder(heisenburg.org>: 'fit' method for 'fit' attribute; 'quality' attribute for creating thumbnails. Also added 'default' attribute in case image is not found.
  • 1.1 - Added 'fit' attribute.
  • 1.0 - Initial release

TrackBack

TrackBack URL for this entry:
http://bradchoate.com/mt/feedback/tb/338

Listed below are links to weblogs that reference MTEmbedImage:

» Pequeña bitacora de fotografias from Sebastian Delmont presenta 'Zonageek.com'
O como prefiero llamarla para ahorrar palabras... miniflog Las fotos que aparecen a la izquierda de la pagina. Que a [Read More]

» Helpful Extensions to MT for Photoblogging? from gessaman.com
Rannie and I were discussing what ways a plugin could extend MT to make photoblogging easier. I already found Brad Choate's MT Embed Image. I'm not really fond of the [Read More]

» Building Image::Magick in Mac OS X Jaguar with Perl 5.8.0 from Tread lightly on the things of earth

I'm trying to get my head around Brad's MTEmbedImage plugin, and it requires ImageMagick and the Image::Magick perl module. (Context: Mac OS X 10.2.3, Perl 5.8.0 built

[Read More]

» This title is with Busey from bakterium.
Design is terribly addictive, that is, once I get into the mood and mindframe for such things. Although I missed... [Read More]

» MT Plugins Installed from Technology Updates
The following MovableType plugins were installed: From Brad Choate IncludeEx - Improves on MT’s Include tag by processing the included file for MT tags. MTAuthors - This plugin allows you to list the authors for your blog. You can also... [Read More]

» MTPhotoGallery from Brandon Fuller
Current version is 0.2 (27 Aug 2003) Contents What this plugin does Installation instructions Image File Name Convention How to use the tags Examples Donate Download Version History To Do Contact What this plugin does This plugin gives you a... [Read More]

» MTPhotoGallery from Brandon Fuller
Current version is 0.2 (27 Aug 2003) Contents What this plugin does Installation instructions Image File Name Convention How to use the tags Examples Donate Download Version History To Do Contact What this plugin does This plugin gives you a... [Read More]

» Photo Albums w/ Movable Type from Andy's Coding Notes
After reading a few articles about how "http://www.brainstormsandraves.com/archives/2003/07/15/creating_an_entire_site_with_movable_type/">Movable Type can do anything. I decided to redo my personal website using... [Read More]

» Photo Albums w/ Movable Type from Andy's Coding Notes
After reading a few articles about how "http://www.brainstormsandraves.com/archives/2003/07/15/creating_an_entire_site_with_movable_type/">Movable Type can do anything. I decided to redo my personal website using... [Read More]

» Photo Albums w/ Movable Type from Andy's Coding Notes
After reading a few articles about how Movable Type can do anything. I decided to redo my personal website using... [Read More]

» Stephenson and more! from The Organization
Just read an interesting review of Quicksilver, Neil Stephenson's new book. I think i've got to pick it up this weekend, my stack of unread books notwithstanding. I'm also impressed by readers that have created the Metaweb - a wiki... [Read More]

» Tweaks from Fresh Bilge
Lately I've been reading web-designers blogs. You'll find a somewhat... [Read More]

» MT image plugins, moderation and other bits... from The Organization
I was having some problems getting the MTEmbedImage plugin to work. I sent a quick email to Brad Choate about where the basename attributes root is. It is the root of the blog. So, if your blog is at www.blog.com/mt... [Read More]

» Photoblog from The Organization
So, there is, believe it or not, some new photos up on the photoblog. I've got it all fixed up to be super easy to post now, and i think Ciara is going to be making some contributions. Now i... [Read More]

» An easy photolog made easier from Tread lightly on the things of earth
mtphoto/archives/000517.html" title="Photolog entry: Dinner bell, no chihuahua">mtphoto/archives/images/IMG_1252_tn-128w.jpg" width="128" height="171" alt="[Granny's dinner bell]" border="0" />I set up my Movable Type photolog a long while ago followin... [Read More]

» PhotoGallery with MTEmbedeImage from Test
MTEmbedImage "> " width="" height=""/>... [Read More]

» Researching Photolog options and I think I'm on my way to developing something interesting! from MiniBlog
http://bradchoate.com/weblog/2002/08/07/mtembedimage... [Read More]

» Bird On Balcony from OrangeyOrangeBlog
Old photo, just scanned and adjusted. This was just a shot from my balcony in Hawaii once. Bird was just sitting there. Probably the 50mm F/1.4 lens... [Read More]

» Bird On Balcony from OrangeyOrangeBlog
Old photo, just scanned and adjusted. This was just a shot from my balcony in Hawaii once. Bird was just sitting there. Probably the 50mm F/1.4 lens... [Read More]

» Rebuild from Stroplog
Using Plugins and MT tags to customise MovableType. [Read More]

» Test of Full Gallery Integration from Development System
This Entry however demonstrates the full integration of a gallery into the CPS, using Brad Choate's MTEmbedImage Plugin - by putting the name of the gallery album (in this case 0302_Africa) into the keywords field in [], Movable Type displays... [Read More]

» Setting up PhotoBlogs: MTEmbedImage from Then each went to his own home
Ok, I've spent several hours to get MTEmbedImage (a thumbnail tool for Movabletype) working, so I thought I'll share it with the world. The stumbling blocks were these: The basename of MTEmbedImage is from the Movabletype directory, and not from... [Read More]

» links for 2005-05-14 from Brianmitchell.com Weblog
..::littleoslo::..blogpoly From Monopoly to Blogopoly (tags: links) Wiki Instiki homepage (tags: wiki) Brad Choate: MTEmbedImage (tags: moveabletype plugin) The... [Read More]

» Links for 2005-05-14 from Brianmitchell.com Weblog
..::littleoslo::..blogpoly From Monopoly to Blogopoly (tags: links) Wiki Instiki homepage (tags: wiki) Brad Choate: MTEmbedImage (tags: moveabletype plugin) The... [Read More]

» Why Movable Type? from life's like this - avianto's journal
Thomas already wrote his reason why he is still using Movable Type. Now I think it is my turn to... [Read More]

» Hacking Movable Type from A Whole Lotta Nothing
Hacking Movable Type is a book I contributed a couple chapters that has just been released. If you've been using MT for a while and wonder how you could tweak it out just a bit more, or completely write... [Read More]

» Fun With MTPhotoGallery from groundglass
funwithmtphotogallery... [Read More]

18 Comments

jeremy w said:

Brad- wow. looks great. I hope to play with it next week and explore all its features. what about such things as adding a watermark or batch processing? possible?
Also, I see Ben Trott has written a plugin for MT to scrape a list off NetFlix... what about a general HTML scraper that is configurable by the user? for example, you supply a URL, a start code, an end code, maybe a string to match/include and it pulls the html/text from the site into yours? I'll also post this request on the MT Forum page...
Thanks!

bayoe said:

Hey Brad,...

I can't use Image::Magick because I hosted on company hosting which didn't support Image::Magick.

I want to use Netpbm (http://netpbm.sourceforge.net) and I downloaded on my computer. But I don't know how to use on my account. Please tell me how to install it.

Thank you very much.

Brad Choate said:

Currently, this plugin doesn't support NetPBM. I have NetPBM installed on my server in addition to Image::Magick, so I might add support for NetPBM with a future release.

Joe Cooper said:

I can't seem to get this to work. I've simply embeded your sample in my index.html template. When I view the resulting source (my site's index.html) there is no image. Any ideas? I've got all the perl installed and mt-check.cgi reports nothing missing.

Thanks,

Joe

bug said:

Not sure I get the concept of this plugin (in advance of installing it). If I used the demonstration code in my Archive templates (all but IndividualEntry Archive) & Index templates... any image I post in Main Entry Text would be read, and a thumbnail of the image (found or made) would be displayed on those pages, but on the Individual Entry Pages I would get the full sized image. ? I would post to Individual Entry (Main Entry Text) with normal '

Does the plugin deal with the image and leave any surrounding text as is, or do you need to reserve Main Entry Text for just the image and use Addional Entry Text for further info?

...just want to get an idea if this will do what I'm looking for before I rip up the carpet heh. I am hoping to end up with something of a portfolio of artwork (images are already ftp'd to server) as a category in my blog. maybe I would need to make a seperate blog for this and link to it from the main blog since the other categories won't need the tags?

Any more info appreciated. Thx much~bug

(I really appreciate your site for MT info)

bug said:

oops that should have read:... "with normal 'img src=' html tags? "

thx~bug

Nifty code, Brad. Thanks much.
I'm trying to combine a couple of your creations into a macro that will do some great stylesheet magic with an image. Essentially, I'm trying to use EmbedImage within a macro, with some macro attributes. Am I right in thinking that I can't do:


<MTEmbedImage basename="[MTMacroAttr name='path']" height="40" thumbsuffix="-thumb">
. . . etc.

because MTMacroAttr won't expand? The whole EmbedImage tag comes out blank.

Erica said:

Hey Brad! Decided to give this another try! I had a ton of problems the first time I tried to install this and talked to you a bit about it but nothing ever came of it, but between you releasing a new version, MT being upgraded to a new version, and me moving servers, when I messed with it tonight, it worked! Huz-zah!

Thanks for the wonderful plugin!

Casey said:

Hey this plugin is great. It was tough to set up, but once I got it going, I'm loving it. I now have MT set up to work like this:

1. Click "Upload file" in MT administration
2. In the location, I just put a folder name where I would like the image saved
3. Click "create entry" from the upload
4. The path to the image is automatically inserted into my Entry Excerpt box like so: "foldername/myuploadedimage.jpg". I then write a description in the extended entry box
5. I'm done! The EmbedImage plugin creates two new files, image-thumb.jpg and image-full.jpg.

I thought this was a faster method of creating photo albums. If anyone wants tips on how to do this, just write me!

Lev said:

Just another quick vote for Net::PBM.

Paul said:

And yet another NetPBM vote! :) This plugin would be really useful but I too do not have ImageMagick installed on my host.

Luke said:

Tags to pull EXIF data from an image file would be really neat.

Is there any way to use global tag attributes with the basename tag? I'd like to be able to "dirify" my entry names to come up with the image's filename:

Entry Name: "Lights Out"
Image Filename: "lights_out.jpg"

<MTEmbedImage basename="images/[MTEntryTitle dirify="1"].jpg"><img src="<MTEmbedImageFilename>" alt="<$MTEntryTitle$>" <height="<MTEmbedImageHeight>" width="<MTEmbedImageWidth>" /></MTEmbedImage>

Is this possible?

Jim said:

I'm having a problem while using your plugin. I installed it into extlib/bradchoate but i get the long, long error:

Can't locate bradchoate/embedimage.pm in @INC (@INC contains: /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0/i386-linux /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.6.1/i386-linux /usr/lib/perl5/vendor_perl/5.6.1 /usr/lib/perl5/vendor_perl . /usr/local/apache1.3.26-2/ /usr/local/apache1.3.26-2/lib/perl) at plugins/embedimage.pl line 37.

I'm combining this with another plugin (MTPhotoGallery from http://brandon.fuller.name/archives/000218.html#286) that works without your plugin but not with. Any ideas?

Here's the code i'm using:

[table]
[MTPhotoGallery virtual="/blog/images/file" dir="/www/www.mysite.com/blog/images/file" exclude="-THUMB"]
[tr]
[td][MTPhotoGalleryImageDate][/td]
[td]
[MTEmbedImage basename="[MTPhotoGalleryImageLink]" width="150" thumbsuffix="-THUMB"]
[a href="[MTPhotoGalleryImageLink]"]
[img src="[MTEmbedImageThumbFilename]"
width="[MTEmbedImageThumbWidth]"
height="[MTEmbedImageThumbHeight]"/]
[/a]
[/MTEmbedImage]
[/td]
[td][MTPhotoGalleryImageTitle][/td]
[/tr]
[/MTPhotoGallery]
[table]

You rock, Brad!

Daniel said:

I am also trying to use it in conjunction with MTPhotoGallery and get this error upon rebuild w/in MT:

MT::App::CMS=HASH(0x174f6d0) Use of uninitialized value in concatenation (.) or string at pathto\PhotoGallery.pl line 219.

and then obviously no images in the final output.

Related: how can one confirm the Image::Magick installation? I'm running everything local.

James said:

Hi, I just installed this and am trying to do something rather specific with the plug-in.

Basically I will have only ONE entry per month, with one photo. So I am naming the photo "photo_2003_09.jpg" for instance. Is it possible for this plugin to load up the proper image? My goal is to upload the image without having to make any code for it in the entry itself, so it will just load up the photo respective to that month's entry.

Here is my code, which is obviously wrong as far as the "basename" attribute goes :) If you can help me, that'd be great.


<MTEmbedImage basename="[MTDate format="photo_%y_$m.jpg"]">
<img src="<MTEmbedImageFilename>"
width="<MTEmbedImageWidth>"
height="<MTEmbedImageHeight>"
alt=""
border="0" />

I'm very new to the syntax of how these plugins work, so I appreciate any help. Thanks!

Thales said:

I can't make it work if the picture is in the same directory of the template. For instance, if I use this:

[MTEmbedImage basename="[MTEntryExcerpt]"]

The expansion doesn't happen. But if I used something like:

[MTEmbedImage basename="archive/[MTEntryExcerpt]"]

However, this doesn't work for me because my pics and archived pages are in the same dir. What's the solution?

amir said:

I just iinstalled MTEmbedImage on my MT 2.64 setup andit seems to not be interpolating any of the plugin values. When I look at the source of the rendered page I get pretty much exactly what I typed in, with no image name values substituted for plugin variables (i.e. img src="") and my server log shows failures to pull up an image called from my images directory. I reinstalled the plugin and I know that the Textile plugin works fine so I'm kinda stumped at this point.

About

This article was published on August 7, 2002 8:34 PM.

The article previously posted was XHTML 2 Working Draft.

The next article is Touch of Hope.

Many more can be found on the home page or by looking through the archives.

Powered by Movable Type