<?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>Monday By Noon &#187; Cropper UI</title>
	<atom:link href="http://mondaybynoon.com/tag/cropper-ui/feed/" rel="self" type="application/rss+xml" />
	<link>http://mondaybynoon.com</link>
	<description>A resource for Web designers and developers to read about and discuss their craft.</description>
	<lastBuildDate>Mon, 06 Sep 2010 18:50:59 +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>Crop and Resize Images with GD or ImageMagick (v1.1)</title>
		<link>http://mondaybynoon.com/2007/12/17/crop-and-resize-images-with-gd-or-imagemagick-v11/</link>
		<comments>http://mondaybynoon.com/2007/12/17/crop-and-resize-images-with-gd-or-imagemagick-v11/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 08:12:20 +0000</pubDate>
		<dc:creator>Jonathan Christopher</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[Favorites]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Workbench]]></category>
		<category><![CDATA[crop]]></category>
		<category><![CDATA[Cropper UI]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[GD]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[resize]]></category>

		<guid isPermaLink="false">http://mondaybynoon.com/2007/12/17/crop-and-resize-images-with-gd-or-imagemagick-v11/</guid>
		<description><![CDATA[A new GD version has been released to complement the ImageMagick crop and resize with JavaScript and PHP. Crop and resize images from within your browser.]]></description>
			<content:encoded><![CDATA[<p>Over the past couple weeks, <a href="http://mondaybynoon.com/2007/01/22/crop-resize-with-javascript-php-and-imagemagick/#comments">conversation has picked up quite a bit</a> surrounding the <a href="http://mondaybynoon.com/2007/01/22/crop-resize-with-javascript-php-and-imagemagick/#comments">Crop &amp; Resize with JavaScript, PHP, and ImageMagick</a> demo I put together nearly a year ago. There were quite a few requests made in the comments, and there were even some developers beginning to offer their very own code. I&#8217;ve always meant to revisit the example and beef up the feature set a bit, and I&#8217;ve finally been able to do just that.</p>
<h2>Crop and Resize with GD</h2>
<p>Above all, the most asked question was &#8220;<a href="http://mondaybynoon.com/2007/01/22/crop-resize-with-javascript-php-and-imagemagick/#comment-7477">why only ImageMagick</a>&#8220;? I really don&#8217;t have a solid answer for that, other than the project itself was a way for me to get into using <a href="http://www.imagemagick.org/">ImageMagick</a> in a bit more detail than I ever had. I&#8217;m very happy to say that this version (as well as any future versions) now has equivalent ImageMagick <em>and GD</em> installations. You can choose one or the other in both the demo and download sections.</p>
<p><a class="demo" href="http://mondaybynoon.com/examples/crop-resize/1.1/gd/">Demo: GD Crop and Resize v1.1</a></p>
<p><a class="demo" href="http://mondaybynoon.com/examples/crop-resize/1.1/imagemagick/">Demo: ImageMagick Crop and Resize v1.1</a></p>
<p class="update">The demos and downloads have been removed temporarily due to a security issue. Replacements will be linked as soon as possible. Thank you for your patience. Please discontinue use as soon as possible until a revision has been posted.</p>
<p>Converting to <a href="http://www.boutell.com/gd/">GD</a> wasn&#8217;t a major undertaking thanks to the helpful comments on version 1.0. It did take some time getting the slider to properly convey dimensions that would result in an accurate recreation of the image. One thing I have noticed is that the GD version seems to result in lower quality output when compared directly to ImageMagick. If you&#8217;ve got a server with both GD and ImageMagick installed, take a minute to use the same image in both demos to see what the differences are. I plan on looking into this much further, but if you&#8217;re a bit more knowledgeable on the subject, I&#8217;d love to hear what you have to say. Could the answer be that ImageMagick is simply a superior piece of software? I noticed that GD gives you the option to control the quality of images when using certain functions, so I left image output at 90% for the time being (the default is 75%).</p>
<p>If you have any positive or negative experiences with the new GD version, please feel free to post your findings either below, or in an email to me. I&#8217;d be greatly appreciative of any data that comes through.</p>
<h3>Updates to the server side</h3>
<p>There were a number of fixes that needed to be done to the server side of things straight away. First and foremost was Linux dependency. I must admit, a Windows server didn&#8217;t cross my mind when I was working on version 1.0, so I tried to polish things up a bit in that regard. The <code>mv</code> lines have been replaced, as well as an update or two elsewhere. There could very well be some more Windows-specific issues to be dealt with, unfortunately I don&#8217;t have any Windows servers at my disposal to test with. Feedback in this area will be particularly helpful.</p>
<p>A small series of updates I made was to the file upload process itself. The example now only accepts files with a MIME type of <code>image/jpeg</code>. Future versions will allow for more image formats, but I&#8217;d like to do some more research before including it. There are also some checks on the filenames themselves, as there were some issues with particular circumstances in version 1.0.</p>
<p>There was some logic repair regarding the <code>$maxWidth</code> and <code>$maxHeight</code> variables you can set in the first step. As per request, <code>$minWidth</code> and <code>$minHeight</code> have also been added. This should allow you to really narrow down what image dimensions will result using these variables in conjunction with the <a href="http://www.defusion.org.uk/code/javascript-image-cropper-ui-using-prototype-scriptaculous/">Cropper UI</a>. One issue that has not been included yet is taking the minimum and maximum values set in the first step into account when users have reached the resize stage of version 1.1. This will be handled in a future release.</p>
<p>Finally, the last noticeable feature to be added server side was the inclusion of <a href="http://mondaybynoon.com/2007/01/22/crop-resize-with-javascript-php-and-imagemagick/#comment-25838">image rotation</a>. When the final image is presented, image rotations of 90, 180, and 270 degrees will be available as well. You&#8217;re able to pull apart the code to retrieve which image you&#8217;d like to use, and can also include auto-generation using a form whenever you&#8217;d like. This was a larger hill to climb when it came to GD as none of the servers I have access to had PHP compiled with GD bundled, therefore giving me no access to <a href="http://www.php.net/imagerotate"><code>imagerotate()</code></a>. As reflected in the source, <a title="Alternative PHP function for imagerotate()" href="http://www.php.net/manual/en/function.imagerotate.php#73446">a function was written as an alternative</a>, and appears to work just fine. It checks to see if <code>imagerotate()</code> is available before taking the extra <abbr title="Central Processing Unit">CPU</abbr> cycles doing it &#8216;by hand&#8217;.</p>
<p><span id="more-113"></span></p>
<h3>Updates to the <a href="http://www.defusion.org.uk/code/javascript-image-cropper-ui-using-prototype-scriptaculous/">Cropper UI</a></h3>
<p>I can&#8217;t credit <a href="http://www.defusion.org.uk/">Dave Spurr</a> enough for his <a href="http://www.defusion.org.uk/code/javascript-image-cropper-ui-using-prototype-scriptaculous/">Cropper UI</a> that powers the entire front end of the cropping mechanism this installation provides. He had made a number of updates after my version 1.0 release, so first things first I went ahead and upgraded to his most recent version.</p>
<p>The second most asked for feature was a specific alteration to the Cropper UI itself. Whether it be minimum dimensions, maximum dimensions, or something else, it seemed like many people would like to use the script, but the openness of the Cropper UI was in fact a limitation. I made an effort to indicate that Dave Spurr included many of the requested features right out the box and documented them well on his website. To help with the version 1.1 demo, I&#8217;ve included a few Cropper UI instances to demonstrate its robustness. When you check out the demo, you&#8217;ll see a new option to choose the crop type you&#8217;d like to use. I&#8217;ve included the following by default:</p>
<dl>
<dt>Basic crop</dt>
<dd>Includes the most basic version of the Cropper UI. Unrestricted as far as crop dimension is concerned.</dd>
<dt>Ratio (16:9)</dt>
<dd>A 16:9 ratio will be applied to the Cropper UI. There are no restrictions for width or height.</dd>
<dt>Minimum Dimensions (200&#215;200)</dt>
<dd>The Cropper UI will require a minimum 200px by 200px crop area and will not allow anything less.</dd>
<dt>Minimum Dimensions (200&#215;200) with Ratio (1:1)</dt>
<dd>The Cropper UI will require a minimum 200px by 200px crop area and will not allow anything less. It will also apply a 1 to 1 ratio when adjusting the crop area.</dd>
<dt>Maximum Dimensions (200&#215;200)</dt>
<dd>The Cropper UI will require a maximum 200px by 200px crop area and will not allow anything less.</dd>
<dt>Maximum Dimensions (200&#215;200) with Ratio (1:1)</dt>
<dd>The Cropper UI will require a maximum 200px by 200px crop area and will not allow anything less. It will also apply a 1 to 1 ratio when adjusting the crop area.</dd>
<dt>Fixed Dimensions (200&#215;200)</dt>
<dd>You&#8217;re provided with a crop area at a fixed size of 200px by 200px. The drag handles are also removed as an added convenience.</dd>
<dt>Minimum Dimensions (100&#215;100) &amp; Maximum Dimensions (200&#215;200)</dt>
<dd>With this option, you&#8217;re limited to a crop area range scaling from 100px by 100px to 200px by 200px.</dd>
</dl>
<p>The Cropper UI is quite impressive in and of itself as you can see by the number of options you can apply by changing some values. For example, one thing I didn&#8217;t include in the demo is a Cropper UI that is limited to minimum and maximum dimensions as well as an aspect ratio of 1:1. You can easily invoke a Cropper UI with these attributes by creating a new file (<code>lib/init_cropper/min_max_ratio.js</code> for example) and inserting the following:</p>
<pre class="sh_javascript"><code>function onEndCrop(coords, dimensions) {
	$('cropX').value = coords.x1;
	$('cropY').value = coords.y1;
	$('cropWidth').value = dimensions.width;
	$('cropHeight').value = dimensions.height;
}

Event.observe( window, 'load', function() {
	new Cropper.Img(
		'cropImage', {
			ratioDim: { x: 1, y: 1 },
			minWidth: 200,
			minHeight: 200,
			maxWidth: 300,
			maxHeight: 300,
			onEndCrop: onEndCrop
		}
	);
});</code></pre>
<p>Swapping in this JavaScript would invoke a new Cropper UI for your image with a minimum dimension of 200px by 200px, a maximum dimension of 300px by 300px, as well as an aspect ratio of 1:1. Going further, you&#8217;re also able to specify a minimum or maximum for a height or width alone. This will result in a Cropper UI with handles only on the top and bottom if you wish. I would definitely suggest checking out the official website for <a href="http://www.defusion.org.uk/code/javascript-image-cropper-ui-using-prototype-scriptaculous/">Dave Spurr&#8217;s Cropper UI</a> for more details</p>
<h3>Download &amp; installation instructions</h3>
<p>Installation is very straightforward. Download links to follow.</p>
<ol>
<li>Download the GD or ImageMagick version</li>
<li>Extract</li>
<li>Upload to your webserver</li>
<li><em>Give write permissions</em> to the <code>working</code> folder and subfolders</li>
<li>Begin using the demo</li>
</ol>
<p><a class="zipDownload" href="http://mondaybynoon.com/examples/crop-resize/1.1/download/crop-resize-gd-1.1.zip">Download GD Crop and Resize v1.1 (.zip)</a></p>
<p><a class="zipDownload" href="http://mondaybynoon.com/examples/crop-resize/1.1/download/crop-resize-imagemagick-1.1.zip">Download ImageMagick Crop and Resize v1.1 (.zip)</a></p>
<p class="update">The demos and downloads have been removed temporarily due to a security issue. Replacements will be linked as soon as possible. Thank you for your patience. Please discontinue use as soon as possible until a revision has been posted.</p>
<p>Many times, if you&#8217;re experiencing odd behavior such as pages turning up blank, there is an issue with write permissions on your server. The demo will need write access to the directory in which it is stored as well as the <code>working</code> folder and all folders within it. Errors with the code itself will more than likely be output to the screen. If that happens, please feel free to post your errors at your earliest convenience.</p>
<h3>What about AJAX?</h3>
<p>Another request that popped up more than once was a request for an AJAX version, something that didn&#8217;t require the page to reload. I thought about working out something such as that but quickly dismissed it, at least for now. My intention with this project was to provide something which would be used by the widest audience possible. Too many times have I seen examples too far into their own development to prevent me from writing something from scratch. In my opinion, an AJAX version of this example would prevent easy adoption and inclusion for many developers. AJAX may be a possibility for a future version, but I&#8217;d like to seriously consider as many angles as possible. This directly relates to the (lack of) design when looking at the demonstration. I wanted to keep things minimal in order to create the least work for anyone who wants to try incorporating this into something they&#8217;ve written.</p>
<p>I hope at the very least, the GD version presents itself as useful to at least a few people over the coming months. I do plan continuing work on future version, I simply hope it doesn&#8217;t take as long as this revision has. Please provide any comments you&#8217;d like, especially bug reports, and enjoy the demo!</p>
]]></content:encoded>
			<wfw:commentRss>http://mondaybynoon.com/2007/12/17/crop-and-resize-images-with-gd-or-imagemagick-v11/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 6/15 queries in 0.007 seconds using disk

Served from: mondaybynoon.com @ 2010-09-09 13:05:17 -->