<?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>Ben Snider &#187; Shell Scripting</title>
	<atom:link href="http://www.bensnider.com/category/shell-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bensnider.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 05 May 2010 16:33:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>ImageMagick Split and Join a Sprite Sheet</title>
		<link>http://www.bensnider.com/2010/02/09/imagemagick-split-and-join-a-sprite-sheet/</link>
		<comments>http://www.bensnider.com/2010/02/09/imagemagick-split-and-join-a-sprite-sheet/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 23:03:39 +0000</pubDate>
		<dc:creator>BenSnider</dc:creator>
				<category><![CDATA[Game Dev]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>

		<guid isPermaLink="false">http://www.bensnider.com/?p=154</guid>
		<description><![CDATA[Continuing the Flixel theme that seems to be brewing here, I found a good way to transform images from full dimension art to sprite sheets. This is useful when converting an image into a sheet compatible with the Flixel tile and map system. In my case I am using it to split up background images [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the <a href="http://wiki.github.com/AdamAtomic/flixel/">Flixel</a> theme that seems to be brewing here, I found a good way to transform images from full dimension art to sprite sheets. This is useful when converting an image into a sheet compatible with the Flixel tile and map system. In my case I am using it to split up background images so I can use them in <a href="http://www.tbam.com.ar/utility--flan.php">Flan</a>, the Flixel map editor.</p>
<p>I&#8217;m just using the standard <a href="http://www.imagemagick.org/script/index.php">ImageMagick</a> tools <em><a href="http://www.imagemagick.org/script/convert.php">convert</a></em> and <em><a href="http://www.imagemagick.org/script/montage.php">montage</a></em> to split and join the images, as well as some bash-fu to sort files properly. I am using <a href="http://www.cygwin.com/">Cygwin</a> to get bash tools on my Windows machine.</p>
<p>The first command is used to split up the main image. The only constraints here are that the resulting tiles must be square, and that they don&#8217;t exceed the width limit for Flash <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html">BitmapData</a> objects. So here we simply are cropping the image into square tiles.</p>
<pre class="prettyprint">convert full.png -crop 32x32 tiles.png</pre>
<p>&nbsp;<br />
This will spit out a bunch of images in the current folder named tiles-%d.png where %d is the 0 based index of the tile. This also assumes that the width and height of the full.png image are divisible by 32 without remainder.</p>
<p>The next command we need is to stitch the images back together. For this we will use the handy <em>montage</em> tool to tile the images into one big sheet. We just pass it a sorted list of names and tell it to make 1 row with as many columns as it needs (the x1 parameter). Sorting is not entirely necessary but using the default bash globbed format will result in tiles that should be at the end of the image randomly at the beginning (try it before this step by noting the output of `ls tiles*.png`).</p>
<pre class="prettyprint">files=$(ls tiles*.png | sort -t '-' -n -k 2 | tr '\n' ' ')
montage $files -tile x1 -geometry 32x32+0+0 sheet.png</pre>
<p>&nbsp;<br />
If all went well we should see, inside the current directory, an image with all of our separate tile sprites in a single row in order from the original image from left to right and top to bottom.</p>
<p>This technique is also useful for converting &#8220;liberated&#8221; sprite sheets that have more than one row, into single row sprite sheets that flixel can handle out of the box.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bensnider.com/2010/02/09/imagemagick-split-and-join-a-sprite-sheet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting the Owner of a File in Linux</title>
		<link>http://www.bensnider.com/2008/02/25/getting-the-owner-of-a-file-in-linux/</link>
		<comments>http://www.bensnider.com/2008/02/25/getting-the-owner-of-a-file-in-linux/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 21:40:38 +0000</pubDate>
		<dc:creator>BenSnider</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>

		<guid isPermaLink="false">http://www.bensnider.com/2008/02/25/getting-the-owner-of-a-file-in-linux/</guid>
		<description><![CDATA[Ran across this problem where I needed root to execute a script as whoever owns it. The solution is simple and should work most everywhere. Basically it just uses the standard &#8220;stat&#8221; program and uses the print formatting option to only output the name of the owner. Here I use bash to get the owner: [...]]]></description>
			<content:encoded><![CDATA[<p>Ran across this problem where I needed root to execute a script as whoever owns it. The solution is simple and should work most everywhere. Basically it just uses the standard &#8220;stat&#8221; program and uses the print formatting option to only output the name of the owner. Here I use bash to get the owner:</p>
<pre class="prettyprint">
#!/bin/bash
username=`stat ${1} --printf %U`
echo "The owner of ${1} is ${username}";
exit 0;</pre>
<p>And a sample run looks like:</p>
<pre class="prettyprint">
$ ./whoOwnsIt.sh testfile.txt
The owner of testfile.txt is ben.</pre>
<p>Making root run it as the user&#8217;s owner is then trivially done with:</p>
<pre class="prettyprint">
su ${username} ${cmd}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bensnider.com/2008/02/25/getting-the-owner-of-a-file-in-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
