Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7572809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:01:11+00:00 2026-05-30T16:01:11+00:00

I’m (loosely) following RailsCasts tutorial #182 , which uses Paperclip, ImageMagick, and Jcrop to

  • 0

I’m (loosely) following RailsCasts tutorial #182, which uses Paperclip, ImageMagick, and Jcrop to allow custom cropping of uploaded images.

As I’m using Amazon S3 for file storage, I’ve had to rejigger parts of the tutorial to suit. Everything seems to be working perfectly except for the fact that the cropped version of my image isn’t being reprocessed (or the result of that reprocess is not re-uploaded to S3)–so after the cropping process, I’m left with the same image I originally uploaded (this is true for all image sizes I store for each image).

Here is my Feature (as in Feature Image) model:

class Feature < ActiveRecord::Base
  require "#{Rails.root}/lib/paperclip_processors/cropper.rb"

  attr_accessible    :image_file_name, :image
  attr_accessor      :crop_x, :crop_y, :crop_w, :crop_h
  after_update       :reprocess_image, :if => :cropping?

  if Rails.env == "production"
  S3_CREDENTIALS = { :access_key_id     => '<REDACTED>',
                     :secret_access_key => '<REDACTED>',
                     :bucket            => "<REDACTED>"}
  else
  S3_CREDENTIALS = { :access_key_id     => '<REDACTED>',
                     :secret_access_key => '<REDACTED>',
                     :bucket            => "<REDACTED>"}
  end

  has_attached_file :image,
                    :styles          => { :small => "240x135>", :croppable => "960x960>", :display => "960x540>" },
                    :processors      => [:cropper],
                    :storage         => :s3,
                    :s3_credentials  => S3_CREDENTIALS,
                    :path            => "features/:id/:style.:extension"

  validates_attachment_content_type :image, :content_type => ['image/jpeg', 'image/gif', 'image/png',
                                                              'image/pjpeg', 'image/x-png'], 
                                            :message => 'must be a JPEG, GIF or PNG image'

  def cropping?
    !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
  end

  def image_geometry(style = :original)
    @geometry ||= {}
    path = (image.options[:storage]==:s3) ? image.url(style) : image.path(style)
    @geometry[style] ||= Paperclip::Geometry.from_file(path)
  end

  private

  def reprocess_image
    image.reprocess!
  end
end

Here is my ‘cropper.rb’ (Paperclip processor):

module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command
        crop_command + super.sub(/ -crop \S+/, '')
      else
        super
      end
    end

    def crop_command
      target = @attachment.instance
      if target.cropping?
        " -crop '#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}'"
      end
    end
  end
end

The relevant actions of my FeaturesController:

class FeaturesController < ApplicationController

  def new
    @feature = Feature.new
  end

  def create
    @feature = Feature.new(params[:feature])
    if @feature.save
      if params[:feature][:image].blank?
        flash[:notice] = "New feature added!"
        redirect_to @feature
      else
        render :crop
      end
    else
      @title = "Add a New Feature"
      render :new
    end
  end

  def edit
    @feature = Feature.find(params[:id])
    @title = "Edit #{@feature.headline}"
  end

  def update
    @feature = Feature.find(params[:id])
    if @feature.update_attributes(params[:feature])
      if params[:feature][:image].blank?
        flash[:notice] = "Feature updated!"
        redirect_to @feature
      else
        render :crop
      end
    else
      @title = "Edit Feature"
      render :edit
    end
  end
end

And the relevant lines of my ‘crop.html.erb’ view:

<% content_for :javascript_includes do %>
    <%= javascript_include_tag 'jquery.Jcrop.min' %>
    <script type="text/javascript" charset="utf-8">
    $(function() {
        $('#cropbox').Jcrop({
            onChange: update_crop,
            onSelect: update_crop,
            setSelect: [0, 0, 960, 540],
            aspectRatio: 960/540
        });
    });

    function update_crop(coords) {
        var ratio = <%= @feature.image_geometry(:original).width %> / <%= @feature.image_geometry(:croppable).width %>;
        $("#crop_x").val(Math.round(coords.x * ratio));
        $("#crop_y").val(Math.round(coords.y * ratio));
        $("#crop_w").val(Math.round(coords.w * ratio));
        $("#crop_h").val(Math.round(coords.h * ratio));
    };
    </script>
<% end %>
<% content_for :style_includes do %>
    <%= stylesheet_link_tag 'jquery.Jcrop', :media => 'screen' %>
<% end %>

<%= image_tag @feature.image.url(:croppable), :id => "cropbox" %>

<% form_for @feature do |f| %>
    <% for attribute in [:crop_x, :crop_y, :crop_w, :crop_h] %>
        <%= f.hidden_field attribute, :id => attribute %>
    <% end %>
    <p><%= f.submit "Crop" %></p>
<% end %>

The problem is not that there’s an error with the custom crop (offset, crop area, etc.), it’s that there is no crop happening when I click ‘crop’–I’m just left with the images I got from the original upload/process. It doesn’t appear that ‘image.reprocess!’ is happening at all (or the results of the reprocess aren’t being saved to S3).

Why might that be, and what can I do about it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:01:13+00:00Added an answer on May 30, 2026 at 4:01 pm

    Don’t know if this is the same but I had a problem with the reprocessing and fixed it by following the answer here:

    paperclip error while reporcessing after rails 3 upgrade

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.