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:
- Movable Type 2.21 or later
- ImageMagick and the Image::Magick perl module. Please refer to the Movable Type documentation regarding this requirement.
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
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!
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.
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.
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
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)
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.
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!
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!
Just another quick vote for Net::PBM.
And yet another NetPBM vote! :) This plugin would be really useful but I too do not have ImageMagick installed on my host.
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?
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!
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.
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!
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?
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.