From c791ee9f3c0f6ae359bd33658c943167c742de72 Mon Sep 17 00:00:00 2001 From: Torsten Date: Fri, 30 Dec 2022 14:26:29 +0200 Subject: [PATCH] resize, or cropping, with offsets --- app/controllers/merged/images_controller.rb | 7 ++++--- app/views/merged/images/_editor.haml | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/merged/images_controller.rb b/app/controllers/merged/images_controller.rb index 4b7c83d..a23c1e7 100644 --- a/app/controllers/merged/images_controller.rb +++ b/app/controllers/merged/images_controller.rb @@ -31,9 +31,10 @@ module Merged message = "Image was scaled" mini.resize( "#{params[:scale]}%") else - mini.resize( "#{new_width}x#{new_height}+#{x_offset}+#{y_offset}") - # x offset to the right - # y offset from top down + size = "#{params[:size_x]}x#{params[:size_y]}+#{params[:off_x]}+#{params[:off_y]}" + puts size + mini.crop( size ) + message = "Image was resized" end @image.edit_save(current_member.email) @image.init_file_data diff --git a/app/views/merged/images/_editor.haml b/app/views/merged/images/_editor.haml index 8d1c23e..1566ba1 100644 --- a/app/views/merged/images/_editor.haml +++ b/app/views/merged/images/_editor.haml @@ -9,6 +9,16 @@ %range-slider.mx-20.justify-self-start{"v-model":"scale" , ":min":20, ":max":100 , ":step": "0.1"} Scale {{scaled_x}} x {{scaled_y}} + + = form_tag( merged.image_path , {method: :patch } ) do + %input{ hidden: true , id: :width_id , name: :size_x , "v-bind:value": "size_x" } + %input{ hidden: true , id: :height_id , name: :size_y , "v-bind:value": "size_y" } + %input{ hidden: true , id: :off_x_id , name: :off_x , "v-bind:value": "off_x" } + %input{ hidden: true , id: :off_y_id , name: :off_y , "v-bind:value": "off_y" } + %button.mt-3.bg-cyan-200{class: button_classes , name: :type , value: 'resize'} Resize + + %label Ratio {{ratio}} : 1 + .flex.justify-between %range-slider.justify-self-start.horizontal{"v-model":"off_y" , ":min":0, ":max":"size_y" , ":step": "1"} Y Offset {{off_y}} @@ -36,8 +46,8 @@ @size_x = @image_data[:width] @size_y = @image_data[:height] end - def scole(ignored) - return @scale + def ratio + ((@size_x / @size_y)*100).to_i / 100 end def scaled_x (@initial_x * @scale / 100).to_i