Class: Paperclip::RailsAdminJcropper

Inherits:
Thumbnail
  • Object
show all
Defined in:
lib/rails_admin_jcrop/asset_engine/paperclip.rb

Instance Method Summary collapse

Instance Method Details

#crop_paramsObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rails_admin_jcrop/asset_engine/paperclip.rb', line 54

def crop_params
  target = @attachment.instance

  w = target.crop_w.to_i
  h = target.crop_h.to_i
  x = target.crop_x.to_i
  y = target.crop_y.to_i

  x = "+#{x}" if x >= 0
  y = "+#{y}" if y >= 0
  geometry = "#{w}x#{h}#{x}#{y}"

  geometry
end

#transformation_commandObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rails_admin_jcrop/asset_engine/paperclip.rb', line 36

def transformation_command
  if @attachment.instance.rails_admin_cropping?
    ary = super
    if i = ary.index('-crop')
      ary.delete_at i+1
      ary.delete_at i
    end

    process_before  = [@attachment.instance.crop_process_before]
    crop            = ['-crop', crop_params]
    process_after   = [@attachment.instance.crop_process_after]

    process_before + crop + process_after + ary
  else
    super
  end
end