Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-05-03 00:51:48

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

soo_image: simple yet powerful image tags

Why another image plugin? This is my concept of how image tags should work in Txp. It’s rather like article context and article forms, but for images. The tags are simple, with not too many attributes (and most of those standard); my goal is for them to feel and behave like core Txp.

The plugin consists of four kinds of tags:

  • Output tags: display images and related info (image author, image name, etc); also EXIF data directly from image files
  • Conditional tags: test a variety of image conditions
  • Controller tag: soo_image_select, does for images what article and article_custom do for articles
  • Pagination tags: for multi-page galleries

Current version: 1.0.b.8, released 2010/12/18

Documentation, download, and examples

Latest changes:

Version 1.0.b.8:

  • New conditional tag, soo_if_image_count
  • soo_image_select now understands global image-category context (new in Txp 4.3.0)

Version 1.0.b.7:

  • Thumbnail height and width attributes (Txp 4.2.0 or later) added automatically, according to default_dimensions preference.

Version 1.0.b.6:

  • New behavior for soo_image: when used outside soo_image_select, and without id or name, article image now takes priority over any images from soo_image_select tags earlier on the page (i.e., persistent context). This gives more predictable behavior in an article list. (Thanks to Adi for spotting this.)
  • New preference setting to enable/disable persistent context.
  • Code cleaning (soo_txp_obj 1.0.b.6 now required).

Last edited by jsoo (2010-12-19 14:51:08)


Code is topiary

Offline

#2 2009-05-03 01:13:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Re: soo_image: simple yet powerful image tags

Looks pretty useful, nice one. Not a million miles away from the image patch I submitted (txp:image_list is analogous to your soo_image_select tag. Though my initial attempt at doing what you have done by offering one tag per ‘column’ was given a lukewarm reception so I consolidated the tags a little into txp:image_info type=“alt|caption|author|ext|etc”). Glad to see images handled consistently and logically though.

Do you have plans to extend this plugin with the new thumbnail dimensions in the database? If so, would that be via a new pair of tags or a thumbnail="1" attribute to soo_image_width/height?

Good stuff. Will have a play when I get a chance.

Last edited by Bloke (2009-05-03 01:14:32)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2009-05-03 02:07:04

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_image: simple yet powerful image tags

Bloke wrote:

… my initial attempt at doing what you have done by offering one tag per ‘column’ was given a lukewarm reception so I consolidated the tags a little into txp:image_info type=“alt|caption|author|ext|etc”).

Easy to do either way, of course. I see the one tag per column approach as more in keeping with the current style of core Txp, but it’s debatable.

Do you have plans to extend this plugin with the new thumbnail dimensions in the database? If so, would that be via a new pair of tags or a thumbnail="1" attribute to soo_image_width/height?

I’m very bad about following the latest developments — didn’t know this was coming. At first thought I tend toward the latter, using a thumbnail attribute. I’ll have to look into what else is on tap. I would certainly like to see some additional image fields, especially for EXIF-type data. Certainly the exposure date.


Code is topiary

Offline

#4 2009-05-03 03:10:58

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: soo_image: simple yet powerful image tags

Yay! Jolly good work.

Last edited by mrdale (2009-05-03 03:11:17)

Offline

#5 2009-05-08 00:10:27

PascalL
Member
From: Switzerland
Registered: 2009-03-09
Posts: 132
Website

Re: soo_image: simple yet powerful image tags

It’s rather like article context and article forms, but for images. […]my goal is for them to feel and behave like core Txp

This has set me in a plugin alert state! If it can do what I suppose, I need it badly! let’s look…

Thank you very much!

Last edited by PascalL (2009-05-08 00:11:42)

Offline

#6 2009-05-12 14:26:58

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: soo_image: simple yet powerful image tags

I love using the Article Image field to associate an article with multiple images, and displaying those with soo_image. Is there any way to output only the URL of a single Article Image when more than one is specified? I only need to grab the URL of the first image for each article.

I decided to use a custom field for this URL, since I might want to use a different image sometime.

Thanks for the awesome plugin!

Last edited by johnstephens (2009-05-12 15:03:39)

Offline

#7 2009-05-12 14:54:56

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_image: simple yet powerful image tags

Try adding this to the plugin code:

function soo_image_url() { 
	$image = _soo_image_by_context();
	if ( $image instanceof Soo_Txp_Img )
		return $image->full_url();
}

This will give you a root-relative URL (such as /images/42.jpg). If the tag (<txp:soo_image_url />) is not in an image form, it will return only the URL of the first article image.

Let me know if that does what you need, and if so I will add it to the next release.

Edit: OK, I’ll hold off adding this for now as personally I don’t need it. But let me know if you change your mind.

Or see this alternative (only works with standard use of the article-image field, i.e., one image per article).

Last edited by jsoo (2009-05-13 17:18:59)


Code is topiary

Offline

#8 2009-05-12 20:14:21

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: soo_image: simple yet powerful image tags

Thanks! I’ll try this out later.

I got this working hassle-free on my development server, but when I deployed the forms to my live server, I got some strange behavior that I can’t account for. It seems like it’s not using my designated form.

Here’s the tag I’m using in my article form:

<txp:soo_image_select form="image-display" />

…and here’s the image-display form:

<txp:soo_image link_rel="lightbox-smd" thumbnail="1" link="1" />

According to the tag-trace, it is finding the correct form:

<txp:soo_image_select form="image-display" />
	[SQL (0.000200986862183): select count(*) from txp_image where id in ('27','29','30','33','31','32')]
	[SQL (0.000166893005371): select * from txp_image where id in ('27','29','30','33','31','32') order by name asc]
	[SQL (0.00016713142395): select Form from txp_form where name='image-display']
	[Form: image-display]
	<txp:soo_image link_rel="lightbox-smd" thumbnail="1" link="1" />
	[Form: image-display]
	<txp:soo_image link_rel="lightbox-smd" thumbnail="1" link="1" />
	[Form: image-display]
	<txp:soo_image link_rel="lightbox-smd" thumbnail="1" link="1" />
	[Form: image-display]
	<txp:soo_image link_rel="lightbox-smd" thumbnail="1" link="1" />
	[Form: image-display]
	<txp:soo_image link_rel="lightbox-smd" thumbnail="1" link="1" />
	[Form: image-display]
	<txp:soo_image link_rel="lightbox-smd" thumbnail="1" link="1" />

But this is the markup it’s creating:

<a href="/images/27.png"><img alt="" /> 
</a> 
<a href="/images/32.png"><img alt="" /> 
</a> 
<a href="/images/33.png"><img alt="" /> 
</a> 
<a href="/images/30.png"><img alt="" /> 
</a> 
<a href="/images/29.png"><img alt="" /> 
</a> 
<a href="/images/31.png"><img alt="" /> 
</a>

No rel, no src. I’m puzzled. My PHP version on the remote server is 5.2.0-8, and on my local server I have 5.2.5.

Offline

#9 2009-05-12 21:30:55

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_image: simple yet powerful image tags

Sorry you’re having this issue. I’m puzzled too. Are you using the same version of the soo_txp_obj plugin on both the local and live installations? Conceivably it is the PHP version — I am running 5.2.4 and 5.2.6 and haven’t tested with anything earlier.

Curious — do any of these images have captions (i.e., something in the Description field)?

Last edited by jsoo (2009-05-12 21:41:17)


Code is topiary

Offline

#10 2009-05-12 22:28:36

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: soo_image: simple yet powerful image tags

jsoo wrote:

Sorry you’re having this issue. I’m puzzled too. Are you using the same version of the soo_txp_obj plugin on both the local and live installations?

Definitely using the same version: 1.0.a4.

Curious — do any of these images have captions (i.e., something in the Description field)?

None of them did. I added some alt-text and a caption to one image in Textpattern, and the alt-text displayed correctly:

<a href="/images/33.png"><img alt="My alt text for image 33!" /> 
</a>

But it still doesn’t seem to be using the image display form specified.

I’ll post again if I have an epiphany. Thanks for your reply— let me know if you think of anything else!

Last edited by johnstephens (2009-05-12 22:29:15)

Offline

#11 2009-05-12 22:59:45

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_image: simple yet powerful image tags

johnstephens wrote:

I added some alt-text and a caption to one image in Textpattern, and the alt-text displayed correctly:

That’s even stranger — that the alt would show, but not the caption.

As I am unable to duplicate the issue, I would need your help to try to debug this. I would certainly understand if you’d rather not. But if you’re up for it, first steps I’d like to try:

Anywhere on your live site, put <txp:soo_image id="33" />. What output does this produce?

This next step will make a mess of whatever page you use for testing, so use an out-of-the-way page. In the soo_image function, there is this block:

	if ( $image instanceof Soo_Txp_Img ) {
		$image_data = $image;
		if ( $thumbnail and !$image->thumbnail )
			return false;
		$image = new Soo_Html_Img($image, $thumbnail, $escape);
	}

Put var_dump($image); at the end of the block. What does the var_dump() show on a page with an article image (still using the article and image form you have shown)?

This is a shot in the dark, but what happens if you replace the above block with this:

	if ( $image instanceof Soo_Txp_Img ) {
		if ( $thumbnail and !$image->thumbnail )
			return false;
		$image_data = $image;
		unset($image);
		$image = new Soo_Html_Img($image_data, $thumbnail, $escape);
	}

Code is topiary

Offline

#12 2009-05-13 02:21:14

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_image: simple yet powerful image tags

From this thread, I can see that perhaps I should use complete URLs instead of root-relative.

The necessary changes are in the soo_txp_obj plugin (which this plugin requires). In the Soo_Html_Img class, __construct() function, the following line:

$a['src'] = '/' . $img_dir . '/' . $a['id'] . ( $thumbnail ? 't' : '' ) . $a['ext'];

change to:

$a['src'] = hu . $img_dir . '/' . $a['id'] . ( $thumbnail ? 't' : '' ) . $a['ext'];

and in the Soo_Txp_Img class, full_url() function, a similar change, from:

return '/' . $img_dir . '/' . $this->id . $this->ext;

to:

return hu . $img_dir . '/' . $this->id . $this->ext;

I’m willing to make this change in the next release, if this is a better solution for some users.


Code is topiary

Offline

Board footer

Powered by FluxBB