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); };