image copy

This commit is contained in:
Torsten 2023-01-01 11:56:11 +02:00
parent 322a9b64a9
commit 93f6a1924b
5 changed files with 61 additions and 49 deletions

View File

@ -30,6 +30,7 @@ module Merged
git = Git.open(Rails.root)
begin
git.checkout_file("HEAD" , "merged")
git.checkout_file("HEAD" , "app/assets/images/cms")
ChangeSet.current.zero
message = "Changes reset"
rescue

View File

@ -2,7 +2,7 @@ require "mini_magick"
module Merged
class ImagesController < MergedController
before_action :set_image, only: %i[ update destroy show copy ]
before_action :set_image, only: %i[ update destroy show scale crop copy ]
def index
@images = Image.all
@ -24,18 +24,27 @@ module Merged
end
def update
mini = MiniMagick::Image.new( @image.full_filename)
if(params[:scale])
message = "Image was scaled"
mini.resize( "#{params[:scale]}%")
else
size = "#{params[:size_x]}x#{params[:size_y]}+#{params[:off_x]}+#{params[:off_y]}"
mini.crop( size )
message = "Image was resized"
end
@image.name = params[:name]
@image.tags = params[:tags]
@image.edit_save(current_member.email)
redirect_to image_path(@image) , notice: "Image updated"
end
def scale
mini = MiniMagick::Image.new( @image.full_filename)
mini.resize( "#{params[:scale]}%")
@image.init_file_data
redirect_to image_path , notice: message
@image.edit_save(current_member.email)
redirect_to image_path(@image) , notice: "Image was scaled"
end
def crop
mini = MiniMagick::Image.new( @image.full_filename)
size = "#{params[:size_x]}x#{params[:size_y]}+#{params[:off_x]}+#{params[:off_y]}"
mini.crop( size )
@image.init_file_data
@image.edit_save(current_member.email)
redirect_to image_path(@image) , notice: "Image was resized"
end
def show

View File

@ -49,9 +49,7 @@ module Merged
image = MiniMagick::Image.new(full_filename)
self.width = image.width
self.height = image.height
file = File.open( full_filename )
self.updated_at = file.birthtime
self.size = (file.size/1024).to_i
self.size = (image.size/1024).to_i
end
def destroy

View File

@ -1,31 +1,29 @@
%section.image
.flex.justify-between.mx-20
%button.my-3.bg-cyan-200{class: button_classes }
=link_to "Copy" , merged.image_copy_path(@image.id)
.flex.justify-between
%div.justify-self-start.ml-20.mr-10
%b Scale {{scaled_x}} x {{scaled_y}}
%br/
%input{":min": 20 , ":max": 100 , ":step": 0.1 , :type => "range",
"v-bind:value": "scale" , "v-on:input" => "handle_scale($event)"}/
= form_tag( merged.image_path , {method: :patch } ) do
%input{ hidden: true , id: :scale_id , name: :scale , "v-bind:value": "scale" }
%button.my-3.bg-cyan-200{class: button_classes , name: :type , value: 'scale'} Scale {{scale}} %
%div.justify-self-start.mx-20
%b Scale {{scaled_x}} x {{scaled_y}}
%br/
%input{":min": 20 , ":max": 100 , ":step": 0.1 , :type => "range",
"v-bind:value": "scale" , "v-on:input" => "handle_scale($event)"}/
= 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.my-3.bg-cyan-200{class: button_classes , name: :type , value: 'resize'} Crop
= form_tag( merged.image_scale_path(image_id: image.id) ) do
%input{ hidden: true , id: :scale_id , name: :scale , "v-bind:value": "scale" }
%button.my-3.bg-cyan-200{class: button_classes} Scale {{scale}} %
%div.mt-2
%b.pr-2 Ratio
%br/
%em {{ratio}} : 1
= form_tag( merged.image_crop_path(image_id: image.id) ) 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.my-3.bg-cyan-200{class: button_classes } Crop
%div.mt-2.ml-32
%b.pr-2 Fix ratio to
%select{ "@change": "set_ratio"}

View File

@ -2,6 +2,9 @@
.text-xl.font-bold.text-gray-900
Image: #{@image.name}
%button.mx-40.hover:bg-cyan-200{class: button_classes }
=link_to "Copy" , merged.image_copy_path(@image.id)
- if Rails.env.development?
= javascript_include_tag "merged/vue.js"
-else
@ -9,23 +12,26 @@
= render "layouts/merged_header"
.flex.gap-2.m-20
%p
.font-bold.mr-2 Name
= @image.name
%p
.mr-2.font-bold Type
= @image.type
%p
.font-bold Size
= @image.size
%p
.font-bold Tags
= @image.tags
%p
.font-bold Ratio
= @image.ratio.round(2)
= @image.aspect_ratio
.flex.m-20
.left.flex.gap-2.mt-3
%p
.mr-2.font-bold Type
= @image.type
%p
.font-bold Size
= @image.size
%p
.font-bold Ratio
= @image.ratio.round(2)
= @image.aspect_ratio
= form_tag( merged.image_path , class: "ml-20 flex" , method: :patch) do
.font-bold.mt-3.mx-4 Name:
= text_field_tag( "name" , @image.name, class: "rounded border-gray-200 text-sm shadow-sm")
.font-bold.mt-3.mx-4 Tags:
= text_field_tag( "tags" , @image.tags, class: "rounded border-gray-200 text-sm shadow-sm")
%button.bg-cyan-200.mx-4{class: button_classes } Update
=render "editor" , image: @image
.flex.gap-2.m-20