20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'app/controllers/crimagify/cropper_controller.rb', line 20
def params_cropper
@img = {}
@img[:parent_element_id] = params[:parent_element_id]
@img[:data_parent] = ImageFunctions::get_data_parent(params[:parent], params[:parent_id]) if params[:parent_fieldset].blank?
@img[:path_image] = ImageFunctions::write_tmp_image(params[:image], params[:parent_id].to_i, params[:parent], @img[:parent_element_id])
else
@img[:parent_fieldset] = params[:parent_fieldset]
@img[:path_image] = ImageFunctions::write_tmp_image(params[:image], params[:parent_id].to_i, params[:parent], @img[:parent_element_id], params[:parent_fieldset])
end
@img[:crop_x] = params[:crop_x] @img[:crop_y] = params[:crop_y] @img[:crop_w] = params[:crop_w] @img[:crop_h] = params[:crop_h] @img[:parent] = params[:parent] if File.exist?(@img[:path_image])
if @img[:data_parent] == 0
@img_new = Crimagify::Image.find_by_parent_id(@img[:data_parent])
@img_new.update_attributes(:image_temporal => File.open(@img[:path_image]),
:crop_x => @img[:crop_x],
:crop_y => @img[:crop_y],
:crop_w => @img[:crop_w],
:crop_h => @img[:crop_h])
@img_new.crop_avatar_temporal
else
if @img[:data_parent].crimagify_images != []
@cond = true
@img[:data_parent].crimagify_images.map{ |image|
if image.image_name == @img[:parent_element_id]
image.update_attributes(:image_temporal => File.open(@img[:path_image]),
:crop_x => params[:crop_x],
:crop_y => params[:crop_y],
:crop_w => params[:crop_w],
:crop_h => params[:crop_h])
image.crop_avatar_temporal
@cond = false
end
}
if @cond
img = ImageFunctions::save_new_image(@img[:path_image], @img[:crop_x], @img[:crop_y], @img[:crop_w], @img[:crop_h], params[:parent], @img[:data_parent].id, @img[:parent_element_id], true)
img.save!
img.crop_avatar_temporal
@img[:data_parent] = ImageFunctions::get_data_parent(params[:parent], params[:parent_id]) end
else
img = ImageFunctions::save_new_image(@img[:path_image], @img[:crop_x], @img[:crop_y], @img[:crop_w], @img[:crop_h], params[:parent], @img[:data_parent].id, @img[:parent_element_id], true)
img.save!
img.crop_avatar_temporal
@img[:data_parent] = ImageFunctions::get_data_parent(params[:parent], params[:parent_id]) end
end
else
puts "No existe el directorio: #{@img[:path_image]}"
end
end
|