Forum | Plugin: Better image handling

You must be logged in to post Login

Plugin: Better image handling

UserPost

11:14 pm
July 21, 2009


William P. Davis

Veazie, Maine

Admin

posts 65

I would like to develop a plugin to update WP's image functionality. Right now images are displayed inline, which is not very elegant is hard to customize effectively. Right now I use the Get_the_Image plugin with custom fields to avoid inline images, but it doesn't work very well. So I'd like to develop a plugin that relies on the WP image browser but attaches images in custom fields. The inline fuction will not be disabled, so you can still insert images directly into posts, but this plugin will allow greater flexibility and speed.

Here are the ideas I have so far. What would you like to see?

  1. Use custom fields
  2. Static photographer credit
  3. Cutline can be changed per photo, but other cutlines appear in photo listing as example.
  4. Tags for photos
  5. No Javascript (CP's image system ran on Javascript and it sucked tremendously).

wpdavis.com | Editor in Chief, The Maine Campus | Associate, CoPress | will@copress.org | 207.660.5342

10:12 am
July 23, 2009


Andrew Spittle

Walla Walla, WA

Moderator

posts 49

Great idea Will. The handling of images was one of the larger frustrations with WordPress that I ran into while redesigning the Pio site this summer; everything just seemed fairly inelegant. I like the outline that you have there and I think that all of those things would be great to implement.

One other thing that could tie in with the static photographer credit would be a way to browse through images by photographer. I don't know how feasible this would be but it would be pretty sweet to see a specific photographers images in a clean and easy way. It could also provide for the ability to greatly expand photo galleries on a site and could turn that photographers archive page into a sort of resume for the rest of the world to see.

Just a thought, I think the other 5 things in that list would be tremendous improvements on the basic WP structure as well.

Andrew – andrew@copress.org – CoPress Hosting Director – http://www.andrewspittle.net

7:45 pm
July 23, 2009


Daniel Bachhuber

Admin

posts 102

A few more ideas to throw into the mix:

  • Ability to automagically resize images and, based on the number of images associated with the post, choose from a template to use for laying out the images (i.e. one big one at the top, and multiple inset).
  • Expose the IPTC metadata (and be able to sort images by that?)
  • Associate images with authors within WordPress such that you could pull a gallery of the author's images into their author.php page template
  • Ability to associate multiple images with such that it can generate a gallery at the top of the post (like the Spokesman-Review)

8:12 pm
July 24, 2009


joey

Silicon Valley

Admin

posts 39

Short and sweet:

My biggest desire for image handling in WP is to be able to associate an image with a post – much the same way you can associate an excerpt.

FWIW: this is a feature that was listed as a voting option for WP 2.9

CoPress Business Director | @joeybaker | byjoeybaker.com

8:28 pm
July 24, 2009


William P. Davis

Veazie, Maine

Admin

posts 65

@joey I'm not sure I understand…

wpdavis.com | Editor in Chief, The Maine Campus | Associate, CoPress | will@copress.org | 207.660.5342

11:30 pm
July 24, 2009


joey

Silicon Valley

Admin

posts 39

I'm refering to this feature

Post thumbnails: Choose an image to appear as a thumbnail with your post/article/excerpt.

Proposed here: http://wordpress.org/development/2009/07/vote-for-2-9-media-features/

CoPress Business Director | @joeybaker | byjoeybaker.com

11:48 pm
July 24, 2009


William P. Davis

Veazie, Maine

Admin

posts 65

Ah, I see. Since the plugin I'm proposing would use custom fields, it would be very easy to put a thumbnail anywhere, or even edit the excerpt so it would automatically be added.

wpdavis.com | Editor in Chief, The Maine Campus | Associate, CoPress | will@copress.org | 207.660.5342

12:07 pm
August 8, 2009


Daniel Bachhuber

Admin

posts 102

I wanted to add another thought to this thread. One of the things that has bugged me in the past about using custom fields for images is that the images then no longer show up in the RSS feed (because they aren't embedded in the post, but rather displayed as a part of the website template). It would be great if the leading image for the post, if you were using custom fields, were added to the start of the post content in the RSS feed. I probably would even use this on my personal blog :)

12:48 am
August 9, 2009


William P. Davis

Veazie, Maine

Admin

posts 65

You can fix that by modifying the_excerpt or the_excerpt_rss, such as putting the following in your template's function.php file:

function new_wp_trim_excerpt($text) { // Fakes an excerpt if needed

if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = 36;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
array_push($words, '…');
$string = "Custom stuff here, such as the image function";
$text = $string.implode(' ', $words);
}
}
return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'new_wp_trim_excerpt');

You can also create a custom rss template, I believe.

wpdavis.com | Editor in Chief, The Maine Campus | Associate, CoPress | will@copress.org | 207.660.5342

11:59 am
August 9, 2009


Daniel Bachhuber

Admin

posts 102

Oh, I actually do a full RSS feed and the code could be simpler than that. With the right filter, you get the

$content

passed into the function. I'd just append

$content .= $the_image_html + $content;

at the beginning of the content and then return the content. It'd be sweet if this was an option in the plugin; I'd start using this over embedding images in the body text.

3:29 am
August 31, 2009


sbressler

Member

posts 15

Post edited 7:30 am – August 31, 2009 by sbressler
Post edited 2:18 pm – August 31, 2009 by sbressler


William P. Davis said:

You can fix that by modifying the_excerpt or the_excerpt_rss, such as putting the following in your template's function.php file:

function new_wp_trim_excerpt($text) { // Fakes an excerpt if needed

if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = 36;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
array_push($words, '…');
$string = "Custom stuff here, such as the image function";
$text = $string.implode(' ', $words);
}
}
return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'new_wp_trim_excerpt');

You can also create a custom rss template, I believe.


Will, thanks for the helpful function. I'm using a version of what you posted to create an "excerpt" for an article if none exists. However, I'd like the excerpt to end in a period (similar to how CP did it). Without doing a full search of the $words array, is there some simple way of popping off words until you get to a period or changing the explode call?

Thanks,
Scott

P.S. I don't mean to hijack this post – this just seemed like an appropriate place to ask the question. My apologies if not.

Update

I actually decided to change this a bit and figured out how to do it. Instead of getting the first x words, I get the first x characters and just search for the last period. This actually fits my use case a bit better, anyway. Here's the code I'm using:

   $excerpt_length = 250;
   $text = substr($text, 0, $excerpt_length); // get the first $excerpt_length characters
   $text = substr($text, 0, strrpos($text, '.') + 1); // cut off $text at the last period (in the first $excerpt_length characters)

8:08 pm
September 2, 2009


sbressler

Member

posts 15

What is the purpose of this line?

$text = str_replace(']]>', ']]>', $text);

12:45 am
September 6, 2009


William P. Davis

Veazie, Maine

Admin

posts 65

I'm not sure, but it's in the original wordpress code.

wpdavis.com | Editor in Chief, The Maine Campus | Associate, CoPress | will@copress.org | 207.660.5342

11:39 pm
September 12, 2009


Mo Jangda

Toronto, ON

Member

posts 35

I'd avoid the traditional use of custom fields that most plugins/themes are apt to do, since it's not a very user-friendly method of adding functionality. By this I mean, having users add a field like "show_post_thumbnail" with a specific value, to acheive a specific outcome. The problem with this is that, for the user, it's often hard to remember what the exact custom field name is and what specific values is supposed to be entered to acheive the desired result. This is especially true and becomes really hard when you have multiple plugins that use custom fields or have many different fields available.

One way around it is to automatically add custom fields to posts, but this is a waste.

Instead, I'd recommend making use of either custom meta_boxes or TinyMCE plugins and/or short_codes to make the process easier for users. Take it one step further and hide the custom fields you're using by prepending them with an underscore (e.g. _show_post_thumbnail).

Any questions/thoughts, let me know.

7:54 am
September 14, 2009


John Myrstad

Member

posts 7

Post edited 11:54 am – September 14, 2009 by John Myrstad


Actually a modification of Stephan Reiters Scissors plugin  is implemented in the latest 2.9 trunk version. Its still early days for that enhancement so I`d like to encourage to make an enhancement plugin to work with the new 2.9 features or to participate in the core enhancement:

http://core.trac.wordpress.org…..cket/10528


Its probably plugin material though.


John Myrstad


10:12 am
September 20, 2009


John Myrstad

Member

posts 7

Post edited 2:12 pm – September 20, 2009 by John Myrstad


Scribu`s Custom Fields Images has some interesting features:


http://wordpress.org/extend/pl…..ld-images/


About the CoPress forum

Most Users Ever Online:

119


Currently Online:

8 Guests

Forum Stats:

Groups: 1

Forums: 7

Topics: 107

Posts: 538

Membership:

There are 151 Members

There have been 2 Guests

There are 5 Admins

There is 1 Moderator

Top Posters:

Chris Ullyott – 66

Mo Jangda – 35

arobinsonwku – 32

laurenmichell – 21

CMLife – 16

sbressler – 15

Administrators: Daniel Bachhuber (102 Posts), William P. Davis (65 Posts), joey (39 Posts), Greg Linch (14 Posts), adam (1 Post)

Moderators: Andrew Spittle (49 Posts)