image copy
This commit is contained in:
parent
322a9b64a9
commit
93f6a1924b
@ -30,6 +30,7 @@ module Merged
|
|||||||
git = Git.open(Rails.root)
|
git = Git.open(Rails.root)
|
||||||
begin
|
begin
|
||||||
git.checkout_file("HEAD" , "merged")
|
git.checkout_file("HEAD" , "merged")
|
||||||
|
git.checkout_file("HEAD" , "app/assets/images/cms")
|
||||||
ChangeSet.current.zero
|
ChangeSet.current.zero
|
||||||
message = "Changes reset"
|
message = "Changes reset"
|
||||||
rescue
|
rescue
|
||||||
|
@ -2,7 +2,7 @@ require "mini_magick"
|
|||||||
|
|
||||||
module Merged
|
module Merged
|
||||||
class ImagesController < MergedController
|
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
|
def index
|
||||||
@images = Image.all
|
@images = Image.all
|
||||||
@ -24,18 +24,27 @@ module Merged
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
mini = MiniMagick::Image.new( @image.full_filename)
|
@image.name = params[:name]
|
||||||
if(params[:scale])
|
@image.tags = params[:tags]
|
||||||
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.edit_save(current_member.email)
|
@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
|
@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
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@ -49,9 +49,7 @@ module Merged
|
|||||||
image = MiniMagick::Image.new(full_filename)
|
image = MiniMagick::Image.new(full_filename)
|
||||||
self.width = image.width
|
self.width = image.width
|
||||||
self.height = image.height
|
self.height = image.height
|
||||||
file = File.open( full_filename )
|
self.size = (image.size/1024).to_i
|
||||||
self.updated_at = file.birthtime
|
|
||||||
self.size = (file.size/1024).to_i
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@ -1,31 +1,29 @@
|
|||||||
|
|
||||||
%section.image
|
%section.image
|
||||||
.flex.justify-between.mx-20
|
.flex.justify-between.mx-20
|
||||||
%button.my-3.bg-cyan-200{class: button_classes }
|
.flex.justify-between
|
||||||
=link_to "Copy" , merged.image_copy_path(@image.id)
|
%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
|
= form_tag( merged.image_scale_path(image_id: image.id) ) do
|
||||||
%input{ hidden: true , id: :scale_id , name: :scale , "v-bind:value": "scale" }
|
%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}} %
|
%button.my-3.bg-cyan-200{class: button_classes} 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
|
|
||||||
|
|
||||||
%div.mt-2
|
%div.mt-2
|
||||||
%b.pr-2 Ratio
|
%b.pr-2 Ratio
|
||||||
%br/
|
%br/
|
||||||
%em {{ratio}} : 1
|
%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
|
%div.mt-2.ml-32
|
||||||
%b.pr-2 Fix ratio to
|
%b.pr-2 Fix ratio to
|
||||||
%select{ "@change": "set_ratio"}
|
%select{ "@change": "set_ratio"}
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
.text-xl.font-bold.text-gray-900
|
.text-xl.font-bold.text-gray-900
|
||||||
Image: #{@image.name}
|
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?
|
- if Rails.env.development?
|
||||||
= javascript_include_tag "merged/vue.js"
|
= javascript_include_tag "merged/vue.js"
|
||||||
-else
|
-else
|
||||||
@ -9,23 +12,26 @@
|
|||||||
|
|
||||||
= render "layouts/merged_header"
|
= render "layouts/merged_header"
|
||||||
|
|
||||||
.flex.gap-2.m-20
|
.flex.m-20
|
||||||
%p
|
.left.flex.gap-2.mt-3
|
||||||
.font-bold.mr-2 Name
|
%p
|
||||||
= @image.name
|
.mr-2.font-bold Type
|
||||||
%p
|
= @image.type
|
||||||
.mr-2.font-bold Type
|
%p
|
||||||
= @image.type
|
.font-bold Size
|
||||||
%p
|
= @image.size
|
||||||
.font-bold Size
|
%p
|
||||||
= @image.size
|
.font-bold Ratio
|
||||||
%p
|
= @image.ratio.round(2)
|
||||||
.font-bold Tags
|
= @image.aspect_ratio
|
||||||
= @image.tags
|
= form_tag( merged.image_path , class: "ml-20 flex" , method: :patch) do
|
||||||
%p
|
.font-bold.mt-3.mx-4 Name:
|
||||||
.font-bold Ratio
|
= text_field_tag( "name" , @image.name, class: "rounded border-gray-200 text-sm shadow-sm")
|
||||||
= @image.ratio.round(2)
|
.font-bold.mt-3.mx-4 Tags:
|
||||||
= @image.aspect_ratio
|
= 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
|
=render "editor" , image: @image
|
||||||
.flex.gap-2.m-20
|
.flex.gap-2.m-20
|
||||||
|
Loading…
Reference in New Issue
Block a user