Insert an image into a WordPress Post with a plugin.

So in a project I’m working on I need to use a normal form to insert a post into the database. My client wanted the form to also add an image to the post. Furthermore, the image must be inserted using normal WordPress methods. The code below is the minimum required to insert an image into the database and attach it to a specific post.

include_once(ABSPATH.'/wp-admin/includes/media.php');
	include_once(ABSPATH.'/wp-admin/includes/file.php');
	include_once(ABSPATH.'/wp-admin/includes/image.php');
	
//	$id is the id of the post being inserted
//	$name is actually the name of the form input that uploaded the file so WP can access it using $_FILE[$name]
	media_handle_upload($name,$id);

If you are inserting a new post, it makes sense to have the line $id = wp_insert_post($post_data); before this.

A friday in my newsreader: Febuary 22.

Occasionally, so many wonderful posts appear in the lull between the Thursday doldrums and the Friday excitation (pun much?) that I have to “link it up…er…mott”.

  1. It turns out that you can see the effects of trawling for fish from space. Do we need any more evidence against it?
  2. Uncertain Principles posts about the backlash from the Virginia Tech shootings: turns out stage plays with fake wooden weapons endanger students…according to some college administrators.
  3. Uncertain principles also wonders if there is any realistic nanotechnology in SciFi writing.
  4. That encrypted hard drive you might have? Worthless now that the encryption can be broken…easily.

Oh and as a side note, anyone else watch one of my favorite video blogs: http://tv.winelibrary.com/?

image credit: Pulpolux !!!

Advanced image resizing software

The image resize software demonstrated in the video is meant to enable a web browser to resize images without removing context or quality. It does this by removing areas of the image deemed less important by using algorithms that detect curved lines instead of normal straight lines. I’m very impressed with the software and I think it will profoundly effect web design and even amateur photography: who hasn’t wanted to erase an ex from pictures?


hat tip:CL Design Blog

Now there was a response video to this that complained about how it will modify the context of photographs and art work, but I don’t think this is really an issue. Some browsers already scale large images if you try to view just the image and users are already used to clicking on thumbnails: both of which allow you to see their original size just by clicking on them. If these same techniques are applied to the images resized through this software, users will learn to click the images to see a full version. The only difference is the thumbnails and rescaled images will still show the elements of the picture: rather than just seeing a few blotches of color in a thumbnail, you will see the important details scaled down, but with the less important details removed.