shuffling code so it can be reused outside the engine
This commit is contained in:
@ -25,34 +25,28 @@ module Merged
|
||||
end
|
||||
|
||||
def copy()
|
||||
image = Image.new name: "#{name}_copy" , type: type , tags: (tags || "")
|
||||
image = Image.new name: "#{name}_copy" , type: type , tags: (tags || "") ,
|
||||
width: width , height: height, size: size
|
||||
Image.insert(image) # assigns next id
|
||||
FileUtils.cp full_filename , image.full_filename
|
||||
image.init_file_data
|
||||
image
|
||||
end
|
||||
|
||||
#save an io as new image. The filename is the id, type taken from io
|
||||
def self.create_new(name , tags, io)
|
||||
original , ending = io.original_filename.split("/").last.split(".")
|
||||
original , end_ = io.original_filename.split("/").last.split(".")
|
||||
magick_image = MiniMagick::Image.read(io)
|
||||
ending = magick_image.type.downcase
|
||||
name = original if( name.blank? )
|
||||
image = Image.new name: name , type: ending , tags: (tags || "")
|
||||
image = Image.new name: name , type: ending , tags: (tags || "") ,
|
||||
width: magick_image.width, height: magick_image.height ,
|
||||
size: (magick_image.size/1024).to_i
|
||||
self.insert(image) # assigns next id
|
||||
full_filename = image.id.to_s + "." + ending
|
||||
File.open(Rails.root.join("app/assets/images/cms/", full_filename), "wb") do |file|
|
||||
file.write( io.read )
|
||||
end
|
||||
image.init_file_data
|
||||
magick_image.write(Rails.root.join("app/assets/images/cms/", full_filename))
|
||||
image
|
||||
end
|
||||
|
||||
def init_file_data
|
||||
image = MiniMagick::Image.new(full_filename)
|
||||
self.width = image.width
|
||||
self.height = image.height
|
||||
self.size = (image.size/1024).to_i
|
||||
end
|
||||
|
||||
def destroy(editor)
|
||||
File.delete self.full_filename
|
||||
delete_save!(editor)
|
||||
|
Reference in New Issue
Block a user