<?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>Quick and Dirty</title>
	<atom:link href="http://www.guoshimin.com/weblog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.guoshimin.com/weblog</link>
	<description></description>
	<lastBuildDate>Thu, 05 Jan 2012 00:25:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Batch editing images</title>
		<link>http://www.guoshimin.com/weblog/?p=388</link>
		<comments>http://www.guoshimin.com/weblog/?p=388#comments</comments>
		<pubDate>Thu, 05 Jan 2012 00:25:02 +0000</pubDate>
		<dc:creator>GSM</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.guoshimin.com/weblog/?p=388</guid>
		<description><![CDATA[I had a bunch of multi-page pdf documents where each page contains an image in the upper-left corner. I needed to move the images closer to the center of the pages. To do this manually would be incredibly painful. Here&#8217;s what I did after some research. First, convert a multi-page pdf into a series of [...]]]></description>
			<content:encoded><![CDATA[<p>I had a bunch of multi-page pdf documents where each page contains an image in the upper-left corner. I needed to move the images closer to the center of the pages. To do this manually would be incredibly painful. Here&#8217;s what I did after some research.</p>
<p>First, convert a multi-page pdf into a series of jpg&#8217;s:</p>
<pre>convert -density 300 abc.pdf abc.jpg</pre>
<p>This will produce <code>abc-0.jpg, abc-1.jpg</code>, etc., one per page. Next comes the interesting part. Fire up gimp, select from menu Filters -&gt; Python-Fu -&gt; Console. Enter the following code.</p>
<pre>import os
def move(glob, x, y):
  num_files, files = pdb.file_glob(glob, 1)
  for file in files:
    image = pdb.gimp_file_load(file, file)
    pdb.gimp_layer_translate(image.active_layer, x, y)
    drawable = pdb.gimp_image_flatten(image)
    new_file_name = os.path.join(os.path.dirname(file), 'modified-' + os.path.basename(file))
    gimp_file_save(image, drawable, new_file_name, new_file_name)</pre>
<p>Then open one of the jpg&#8217;s. Manually move the image to the desired position, and note the offsets in the x and y direction. Next just call the move function with the filename pattern and the offsets. Voila, you have <code>modified-abc-0.jpg, modified-abc-1.jpg</code>, etc.</p>
<p>Finally, compiled the jpg&#8217;s back to a pdf:</p>
<pre>convert modified-abc-*.jpg modified-abc.pdf</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guoshimin.com/weblog/?feed=rss2&#038;p=388</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

