extract uninterlace_png method
This commit is contained in:
parent
6abd0f8db0
commit
46edaed6bc
2 changed files with 18 additions and 11 deletions
|
@ -1,5 +1,7 @@
|
||||||
module Administrateurs
|
module Administrateurs
|
||||||
class AttestationTemplatesController < AdministrateurController
|
class AttestationTemplatesController < AdministrateurController
|
||||||
|
include UninterlacePngConcern
|
||||||
|
|
||||||
before_action :retrieve_procedure
|
before_action :retrieve_procedure
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@ -63,23 +65,14 @@ module Administrateurs
|
||||||
signature_file = params['attestation_template'].delete('signature')
|
signature_file = params['attestation_template'].delete('signature')
|
||||||
|
|
||||||
if logo_file.present?
|
if logo_file.present?
|
||||||
@activated_attestation_params[:logo] = uninterlaced_png(logo_file)
|
@activated_attestation_params[:logo] = uninterlace_png(logo_file)
|
||||||
end
|
end
|
||||||
if signature_file.present?
|
if signature_file.present?
|
||||||
@activated_attestation_params[:signature] = uninterlaced_png(signature_file)
|
@activated_attestation_params[:signature] = uninterlace_png(signature_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@activated_attestation_params
|
@activated_attestation_params
|
||||||
end
|
end
|
||||||
|
|
||||||
def uninterlaced_png(uploaded_file)
|
|
||||||
if uploaded_file&.content_type == 'image/png'
|
|
||||||
chunky_img = ChunkyPNG::Image.from_io(uploaded_file.to_io)
|
|
||||||
chunky_img.save(uploaded_file.tempfile.to_path, interlace: false)
|
|
||||||
uploaded_file.tempfile.reopen(uploaded_file.tempfile.to_path, 'rb')
|
|
||||||
end
|
|
||||||
uploaded_file
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
14
app/controllers/concerns/uninterlace_png_concern.rb
Normal file
14
app/controllers/concerns/uninterlace_png_concern.rb
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
module UninterlacePngConcern
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def uninterlace_png(uploaded_file)
|
||||||
|
if uploaded_file&.content_type == 'image/png'
|
||||||
|
chunky_img = ChunkyPNG::Image.from_io(uploaded_file.to_io)
|
||||||
|
chunky_img.save(uploaded_file.tempfile.to_path, interlace: false)
|
||||||
|
uploaded_file.tempfile.reopen(uploaded_file.tempfile.to_path, 'rb')
|
||||||
|
end
|
||||||
|
uploaded_file
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue