<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Hacking attachment_fu to work with Flash/Flex uploads and crop square images</title>
	<atom:link href="http://blog.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/</link>
	<description>Flex, Ruby, etc. etc.</description>
	<lastBuildDate>Sat, 06 Feb 2010 21:14:13 -0800</lastBuildDate>
	
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Daryth</title>
		<link>http://blog.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/comment-page-1/#comment-1528</link>
		<dc:creator>Daryth</dc:creator>
		<pubDate>Fri, 05 Feb 2010 20:53:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-1528</guid>
		<description>A little bit to late, but you could use
content_type = `file --brief --mime &quot;#{File.join(temp_path)}&quot;`.chomp

Because option `file -bi ...` 
returns  &#039;regular_file&#039;  instead of something like &#039;image/jpeg&#039;  on Mac OS-X</description>
		<content:encoded><![CDATA[<p>A little bit to late, but you could use<br />
content_type = `file &#8211;brief &#8211;mime &#8220;#{File.join(temp_path)}&#8221;`.chomp</p>
<p>Because option `file -bi &#8230;`<br />
returns  &#8216;regular_file&#8217;  instead of something like &#8216;image/jpeg&#8217;  on Mac OS-X</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rich</title>
		<link>http://blog.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/comment-page-1/#comment-593</link>
		<dc:creator>Rich</dc:creator>
		<pubDate>Thu, 11 Dec 2008 17:16:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-593</guid>
		<description>Alan,

It works.  attachment_fu requires default naming of some form variables to make things work.  Be certain that your incoming parameters hash has a filename and uploaded_data parameter set.  In Flex, you can set the name of your uploaded file with

file.upload(request, &quot;uploaded_data&quot;);

where file is a FileReference object.</description>
		<content:encoded><![CDATA[<p>Alan,</p>
<p>It works.  attachment_fu requires default naming of some form variables to make things work.  Be certain that your incoming parameters hash has a filename and uploaded_data parameter set.  In Flex, you can set the name of your uploaded file with</p>
<p>file.upload(request, &#8220;uploaded_data&#8221;);</p>
<p>where file is a FileReference object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://blog.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/comment-page-1/#comment-592</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Mon, 08 Dec 2008 05:41:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-592</guid>
		<description>does this hack even work with latest version of fu plugin anymore????
nothing seems tobe work for me</description>
		<content:encoded><![CDATA[<p>does this hack even work with latest version of fu plugin anymore????<br />
nothing seems tobe work for me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://blog.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/comment-page-1/#comment-591</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Mon, 08 Dec 2008 04:20:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-591</guid>
		<description>It seems lot of people have been able to successfully make use of this blog.
unfortunately i&#039;m still struggling. my questions:

1. how does the rails controller code look like? how are you guys constructing model object out of posted data?

thx</description>
		<content:encoded><![CDATA[<p>It seems lot of people have been able to successfully make use of this blog.<br />
unfortunately i&#8217;m still struggling. my questions:</p>
<p>1. how does the rails controller code look like? how are you guys constructing model object out of posted data?</p>
<p>thx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: acts_as_attachment?attachment_fu???? at ??????</title>
		<link>http://blog.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/comment-page-1/#comment-590</link>
		<dc:creator>acts_as_attachment?attachment_fu???? at ??????</dc:creator>
		<pubDate>Sun, 16 Nov 2008 10:04:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-590</guid>
		<description>[...] Hacking attachment_fu to work with Flash/Flex uploads and crop square images [...]</description>
		<content:encoded><![CDATA[<p>[...] Hacking attachment_fu to work with Flash/Flex uploads and crop square images [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lance</title>
		<link>http://blog.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/comment-page-1/#comment-589</link>
		<dc:creator>Lance</dc:creator>
		<pubDate>Thu, 04 Sep 2008 04:12:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-589</guid>
		<description>Hi,

I&#039;ve integrated these changes you&#039;ve made into the Ruboss &quot;Flexible Rails&quot; 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&#039;t completely finished the Flex part yet, but this tutorial was great.

Here&#039;s the beginnings of a RESTful Flex on Rails social networking site.  Just laying the groundwork a little bit.  &lt;a href=&quot;http://www.systemsofseven.com/blog/make/21&quot; rel=&quot;nofollow&quot;&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.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/comment-page-1/#comment-585</link>
		<dc:creator>Dave Spurr</dc:creator>
		<pubDate>Sat, 19 Apr 2008 19:31:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-585</guid>
		<description>Very helpful, I&#039;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&#039;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â??&#039; (No such file or directory)

I had no idea what was going on as the temp_path was:

/tmp/CGI4338-1

I couldn&#039;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( /\./, &#039;&#039; ) )
if content_type.to_s.match( /.*\/.*/ )
   content_type.to_s
else
   fallback
end

I don&#039;t really like this, but it works (I&#039;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&#039;t mean I spent as long figuring out why the thumbnails weren&#039;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.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/comment-page-1/#comment-588</link>
		<dc:creator>Kevin Thompson</dc:creator>
		<pubDate>Sat, 16 Feb 2008 01:51:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-588</guid>
		<description>I made the following modification for my purposes:

        def resize_image(img, size)
              logger.debug(&quot;Size: #{size.inspect}&quot;)
          size = size.first if size.is_a?(Array) &amp;&amp; size.length == 1
          if size.is_a?(Fixnum) &#124;&#124; (size.is_a?(Array) &amp;&amp; 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(&#039;x&#039;))
              #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(&quot;0x#{shave_off}&quot;)
          end
          image.resize(&quot;#{nu_width}x#{nu_height}&quot;)
          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] &#8211; 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.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/comment-page-1/#comment-587</link>
		<dc:creator>Sam Freiberg</dc:creator>
		<pubDate>Wed, 16 Jan 2008 22:22:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-587</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&#039;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. <img src='http://blog.alastairdawson.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://blog.alastairdawson.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/comment-page-1/#comment-586</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Mon, 14 Jan 2008 21:39:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vixiom.com/2007/12/28/hacking-attachment_fu-to-work-with-flashflex-uploads-and-crop-square-images/#comment-586</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>
