<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Hacking attachment_fu to work with Flash/Flex uploads and crop square images</title>
	<link>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/</link>
	<description>The Vixiom Blog :: Flex &#38; Flash on Rails</description>
	<pubDate>Tue,  2 Dec 2008 03:08:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
		<item>
		<title>By: acts_as_attachment?attachment_fu???? at ??????</title>
		<link>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-63988</link>
		<dc:creator>acts_as_attachment?attachment_fu???? at ??????</dc:creator>
		<pubDate>Sun, 16 Nov 2008 10:04:04 +0000</pubDate>
		<guid>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-63988</guid>
		<description>[...] Hacking attachment_fu to work with Flash/Flex uploads and crop square images [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Hacking attachment_fu to work with Flash/Flex uploads and crop square images [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lance</title>
		<link>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-61269</link>
		<dc:creator>Lance</dc:creator>
		<pubDate>Thu, 04 Sep 2008 04:12:31 +0000</pubDate>
		<guid>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-61269</guid>
		<description>Hi,

I've integrated these changes you've made into the Ruboss "Flexible Rails" framework to allow file uploading (as well as Restful_Authentication) to be possible from Flex to Rails.  Thanks for all of your help.  I haven't completely finished the Flex part yet, but this tutorial was great.

Here's the beginnings of a RESTful Flex on Rails social networking site.  Just laying the groundwork a little bit.  &lt;a href="http://www.systemsofseven.com/blog/make/21" rel="nofollow"&gt;Ruboss Tutorial&lt;/a&gt;

Peace,
Lance</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;ve integrated these changes you&#8217;ve made into the Ruboss &#8220;Flexible Rails&#8221; framework to allow file uploading (as well as Restful_Authentication) to be possible from Flex to Rails.  Thanks for all of your help.  I haven&#8217;t completely finished the Flex part yet, but this tutorial was great.</p>
<p>Here&#8217;s the beginnings of a RESTful Flex on Rails social networking site.  Just laying the groundwork a little bit.  <a href="http://www.systemsofseven.com/blog/make/21" rel="nofollow">Ruboss Tutorial</a></p>
<p>Peace,<br />
Lance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Spurr</title>
		<link>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-52913</link>
		<dc:creator>Dave Spurr</dc:creator>
		<pubDate>Sat, 19 Apr 2008 19:31:31 +0000</pubDate>
		<guid>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-52913</guid>
		<description>Very helpful, I've not had so much trouble working with Flex and anything else since I started trying to upload files, there were so many issues and this was just one of them.

However your fix didn't work for me, it always called the rescue block, so I commented that out and then did some dumping of the various variables, the results for content_type (after the file -bi “#{File.join(temp_path)} part was):

ERROR: cannot open `â??/tmp/CGI4338-1â??' (No such file or directory)

I had no idea what was going on as the temp_path was:

/tmp/CGI4338-1

I couldn't figure this out so I added the following hack to the rescue block:

content_type = Mime::Type.lookup_by_extension( File.extname( self.filename ).gsub( /\./, '' ) )
if content_type.to_s.match( /.*\/.*/ )
   content_type.to_s
else
   fallback
end

I don't really like this, but it works (I've registered the appropriate mime types with Mime::Type.register). Do you have any idea what that error is on the file -bi line.

Anyway it was still a great help to come across this post as it didn't mean I spent as long figuring out why the thumbnails weren't being created.

Thanks again.</description>
		<content:encoded><![CDATA[<p>Very helpful, I&#8217;ve not had so much trouble working with Flex and anything else since I started trying to upload files, there were so many issues and this was just one of them.</p>
<p>However your fix didn&#8217;t work for me, it always called the rescue block, so I commented that out and then did some dumping of the various variables, the results for content_type (after the file -bi “#{File.join(temp_path)} part was):</p>
<p>ERROR: cannot open `â??/tmp/CGI4338-1â??&#8217; (No such file or directory)</p>
<p>I had no idea what was going on as the temp_path was:</p>
<p>/tmp/CGI4338-1</p>
<p>I couldn&#8217;t figure this out so I added the following hack to the rescue block:</p>
<p>content_type = Mime::Type.lookup_by_extension( File.extname( self.filename ).gsub( /\./, &#8221; ) )<br />
if content_type.to_s.match( /.*\/.*/ )<br />
   content_type.to_s<br />
else<br />
   fallback<br />
end</p>
<p>I don&#8217;t really like this, but it works (I&#8217;ve registered the appropriate mime types with Mime::Type.register). Do you have any idea what that error is on the file -bi line.</p>
<p>Anyway it was still a great help to come across this post as it didn&#8217;t mean I spent as long figuring out why the thumbnails weren&#8217;t being created.</p>
<p>Thanks again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Thompson</title>
		<link>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-44454</link>
		<dc:creator>Kevin Thompson</dc:creator>
		<pubDate>Sat, 16 Feb 2008 01:51:38 +0000</pubDate>
		<guid>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-44454</guid>
		<description>I made the following modification for my purposes:

        def resize_image(img, size)
              logger.debug("Size: #{size.inspect}")
          size = size.first if size.is_a?(Array) &#38;&#38; size.length == 1
          if size.is_a?(Fixnum) &#124;&#124; (size.is_a?(Array) &#38;&#38; size.first.is_a?(Fixnum))
            if size.is_a?(Fixnum)
              resize_and_crop(img, size)
            else
              #size[0] == size[1] ? resize_and_crop(img, size[0]) : img.resize(size.join('x'))
              #resize_and_crop_irregular(img, size[0], size[1])
              size[0] == size[1] ? resize_and_crop(img, size[0]) : resize_and_crop_irregular(img, size[0], size[1])
            end
          else
            img.resize(size.to_s)
          end
          self.temp_path = img
        end        

        def resize_and_crop_irregular(image, nu_width, nu_height)
          original_ratio = (image[:width].to_f / image[:height].to_f).to_f
          nu_ratio = (nu_width.to_f / nu_height.to_f).to_f

          if nu_ratio  original_ratio
            new_ratio = (nu_width.to_f / nu_height.to_f).to_f
            corrected_height = (image[:width].to_f / new_ratio).to_f
            shave_off = ((image[:height] - corrected_height)/2).round
            image.shave("0x#{shave_off}")
          end
          image.resize("#{nu_width}x#{nu_height}")
          return image
        end</description>
		<content:encoded><![CDATA[<p>I made the following modification for my purposes:</p>
<p>        def resize_image(img, size)<br />
              logger.debug(&#8221;Size: #{size.inspect}&#8221;)<br />
          size = size.first if size.is_a?(Array) &amp;&amp; size.length == 1<br />
          if size.is_a?(Fixnum) || (size.is_a?(Array) &amp;&amp; size.first.is_a?(Fixnum))<br />
            if size.is_a?(Fixnum)<br />
              resize_and_crop(img, size)<br />
            else<br />
              #size[0] == size[1] ? resize_and_crop(img, size[0]) : img.resize(size.join(&#8217;x'))<br />
              #resize_and_crop_irregular(img, size[0], size[1])<br />
              size[0] == size[1] ? resize_and_crop(img, size[0]) : resize_and_crop_irregular(img, size[0], size[1])<br />
            end<br />
          else<br />
            img.resize(size.to_s)<br />
          end<br />
          self.temp_path = img<br />
        end        </p>
<p>        def resize_and_crop_irregular(image, nu_width, nu_height)<br />
          original_ratio = (image[:width].to_f / image[:height].to_f).to_f<br />
          nu_ratio = (nu_width.to_f / nu_height.to_f).to_f</p>
<p>          if nu_ratio  original_ratio<br />
            new_ratio = (nu_width.to_f / nu_height.to_f).to_f<br />
            corrected_height = (image[:width].to_f / new_ratio).to_f<br />
            shave_off = ((image[:height] - corrected_height)/2).round<br />
            image.shave(&#8221;0x#{shave_off}&#8221;)<br />
          end<br />
          image.resize(&#8221;#{nu_width}x#{nu_height}&#8221;)<br />
          return image<br />
        end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Freiberg</title>
		<link>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-41535</link>
		<dc:creator>Sam Freiberg</dc:creator>
		<pubDate>Wed, 16 Jan 2008 22:22:51 +0000</pubDate>
		<guid>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-41535</guid>
		<description>Hey Alastair! Nice write up. I wish I would have seen your write up for squaring thumbnails. I ended up having the Flash guys do some masking magic on the images, but this would have been better. Oh well. And it's nice to know there are other people out there who just want to push their apps out there in the best, fastest, easiest way possible and get on with the next app. :)</description>
		<content:encoded><![CDATA[<p>Hey Alastair! Nice write up. I wish I would have seen your write up for squaring thumbnails. I ended up having the Flash guys do some masking magic on the images, but this would have been better. Oh well. And it&#8217;s nice to know there are other people out there who just want to push their apps out there in the best, fastest, easiest way possible and get on with the next app. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-41410</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Mon, 14 Jan 2008 21:39:04 +0000</pubDate>
		<guid>http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-41410</guid>
		<description>This was a great help. Thanks for post.


-Mike (guy you met at onAIR who had the music site)</description>
		<content:encoded><![CDATA[<p>This was a great help. Thanks for post.</p>
<p>-Mike (guy you met at onAIR who had the music site)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
