<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flav36rs &#187; image</title>
	<atom:link href="http://flav36rs.com/tag/image/feed/" rel="self" type="application/rss+xml" />
	<link>http://flav36rs.com</link>
	<description>Just another technical blog</description>
	<lastBuildDate>Mon, 12 Sep 2011 16:56:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>WordPress append image dimensions as class names</title>
		<link>http://flav36rs.com/2010/12/05/wordpress-append-image-dimensions-as-class-names/</link>
		<comments>http://flav36rs.com/2010/12/05/wordpress-append-image-dimensions-as-class-names/#comments</comments>
		<pubDate>Sun, 05 Dec 2010 11:53:20 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[dimensions]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[width]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=747</guid>
		<description><![CDATA[When inserting images into post or page content WordPress automatically adds three class name to the image tag along with the other attributes, these are the alignment (alignnone), size (size-full) and the attachment id (wp-image-123). If you need to add &#8230; <a href="http://flav36rs.com/2010/12/05/wordpress-append-image-dimensions-as-class-names/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When inserting images into post or page content WordPress automatically adds three class name to the image tag along with the other attributes, these are the alignment <em>(alignnone)</em>, size <em>(size-full)</em> and the attachment id <em>(wp-image-123)</em>.</p>
<p>If you need to add additional class names to the defaults without having to manually add them every time you insert a new image, you can make use of either the <strong>get_image_tag_class</strong> or <strong>get_image_tag</strong> filters. <span id="more-747"></span></p>
<p>The first of the two filters is <strong>get_image_tag_class</strong>, which allows you to add a value or change the class attribute completely:</p>
<pre lang="php" escaped="true">function add_image_class($class){
	$class .= ' additional-class';
	return $class;
}
add_filter('get_image_tag_class','add_image_class');</pre>
<p>The second function is a little more flexible and provides the ability to alter the image tag completely, thus providing functionality to add the image dimensions to the class names as shown in this example:</p>
<pre lang="php" escaped="true">function add_image_class_dimensions($html, $id, $alt, $title)
{
	if (preg_match('/width="(d+)" height="(d+)"/', $html, $dimensions)) {
		list(,$width, $height) = $dimensions;
		$html = str_replace(
			'class="',
			'class="wp-image-width-'.$width.' wp-image-height-'.$height.' ',
			$html
		);
	}
	return $html;
}
add_filter('get_image_tag', 'add_image_class_dimensions', 10, 4);</pre>
<p>In brief, this function matches the dimensions found within the image tag <em>(width and height)</em> and appends them to the front of the class attribute.</p>
<p>Applying both of these filters will output something similar the following code in the TinyMCE editor:</p>
<pre lang="xhtml" escaped="true">&lt;img class="wp-image-width-200 wp-image-height-100 alignnone size-full wp-image-123" title="Image Title Here" src="/wp-content/uploads/2010/12/my-image.jpg" alt="" width="200" height="100" /&gt;</pre>
<p>To make use of this functionality you will first need to add the filter and function to your theme&#8217;s function.php file. Once this is done, add a new image to your post or page and you will see the custom class names are appended to the image tag. They <strong>will not</strong> be applied to any existing images within your content, you will have to insert them again from the media library for the changes to be applied.</p>
<p>These are only two examples of what results can be achieved, further adjustments and alterations can be easily added using the two get_image_tag filters.</p>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2010/12/05/wordpress-append-image-dimensions-as-class-names/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JS preload image &#8216;bug&#8217; in Opera</title>
		<link>http://flav36rs.com/2009/03/02/js-preload-image-bug-in-opera/</link>
		<comments>http://flav36rs.com/2009/03/02/js-preload-image-bug-in-opera/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 14:48:39 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[opera]]></category>
		<category><![CDATA[preload]]></category>

		<guid isPermaLink="false">http://sha.re.it/?p=181</guid>
		<description><![CDATA[I have recently attempted to load an image in JavaScript (using jQuery) and once loaded get it&#8217;s dimensions. Using the following code I managed to successfully read the width and height properties in FireFox 2/3, IE 6/7, Windows Safari 3/4 &#8230; <a href="http://flav36rs.com/2009/03/02/js-preload-image-bug-in-opera/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have recently attempted to load an image in JavaScript (using <a href="http://jquery.com/">jQuery</a>) and once loaded get it&#8217;s dimensions.</p>
<p>Using the following code I managed to successfully read the width and height properties in <a href="http://www.mozilla-europe.org/en/firefox/">FireFox</a> 2/3, <a href="http://www.microsoft.com/windows/products/winfamily/ie/default.mspx">IE</a> 6/7, <a href="http://www.apple.com/safari/download/">Windows Safari</a> 3/4 and <a href="http://www.google.co.uk/chrome/">Google Chrome</a>, but the dimensions were not available in <a href="http://www.opera.com/">Opera</a> (10).<span id="more-181"></span></p>
<pre lang="javascript">$('<img alt="" />')
	.load(function() {
		$('body').append(this);
		var w = this.width;
		var h = this.height;
		//..
	})
	.error(function() {
		//..
	})
	.attr('src', '/path/to/image.jpg');</pre>
<p>After a fair bit of time playing around trying to debug this small snippet of code, I <em>eventually</em> discovered that if the image was appended to the DOM <strong>after</strong> the width and height had been read then Opera would report the values correctly.</p>
<pre lang="javascript">		var w = this.width;
		var h = this.height;
		$('body').append(this);
		//..</pre>
<p>Simply moving line 3 down to below the reading of dimensions solved this issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2009/03/02/js-preload-image-bug-in-opera/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

