From 02c202fcd3b3f40dd185ab4feb9f1a7215391450 Mon Sep 17 00:00:00 2001 From: Torsten Date: Fri, 30 Dec 2022 00:41:52 +0200 Subject: [PATCH] image scaling --- app/controllers/merged/images_controller.rb | 19 ++++++++++++++++++- app/views/merged/images/_editor.haml | 11 +++++++++-- app/views/merged/images/show.haml | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/controllers/merged/images_controller.rb b/app/controllers/merged/images_controller.rb index cb302d2..4b7c83d 100644 --- a/app/controllers/merged/images_controller.rb +++ b/app/controllers/merged/images_controller.rb @@ -1,3 +1,5 @@ +require "mini_magick" + module Merged class ImagesController < MergedController @@ -19,9 +21,24 @@ module Merged def destroy @image = Image.find(params[:id]) @image.destroy - redirect_to :images , nootice: "Image #{@image.name} deleted" + redirect_to :images , notice: "Image #{@image.name} deleted" end + def update + @image = Image.find(params[:id]) + mini = MiniMagick::Image.new( @image.full_filename) + if(params[:scale]) + 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 + end + @image.edit_save(current_member.email) + @image.init_file_data + redirect_to image_path , notice: message + end def show @image = Image.find(params[:id]) @sections = Section.where(image_id: params[:id].to_i) diff --git a/app/views/merged/images/_editor.haml b/app/views/merged/images/_editor.haml index e2f8545..8d1c23e 100644 --- a/app/views/merged/images/_editor.haml +++ b/app/views/merged/images/_editor.haml @@ -3,8 +3,12 @@ %section.image .flex.justify-center - %range-slider.justify-self-start{"v-model":"scale" , ":min":0, ":max":100 , - ":step": "1"} Scale {{scaled_x}} x {{scaled_y}} == {{scale}} % + = form_tag( merged.image_path , {method: :patch } ) do + %input{ hidden: true , id: :scale_id , name: :scale , "v-bind:value": "scale" } + %button.mt-3.bg-cyan-200{class: button_classes , name: :type , value: 'scale'} Scale {{scale}} % + + %range-slider.mx-20.justify-self-start{"v-model":"scale" , ":min":20, ":max":100 , + ":step": "0.1"} Scale {{scaled_x}} x {{scaled_y}} .flex.justify-between %range-slider.justify-self-start.horizontal{"v-model":"off_y" , ":min":0, ":max":"size_y" , ":step": "1"} Y Offset {{off_y}} @@ -32,6 +36,9 @@ @size_x = @image_data[:width] @size_y = @image_data[:height] end + def scole(ignored) + return @scale + end def scaled_x (@initial_x * @scale / 100).to_i end diff --git a/app/views/merged/images/show.haml b/app/views/merged/images/show.haml index e672fb7..5d62b62 100644 --- a/app/views/merged/images/show.haml +++ b/app/views/merged/images/show.haml @@ -61,5 +61,5 @@ :css .horizontal input { - transform:rotate(270deg); + transform:rotate(90deg); };