class ImageService
require "mini_magick"
def self.tmp_dir
dir = "#{Rails.root}/tmp/image"
FileUtils.mkdir(dir) unless File.exists?(dir)
dir
end
def self.composite(image_paths)
to_path = "#{tmp_dir}/composite_#{SecureRandom.uuid.to_s.strip}.jpeg"
montage_commond = image_paths + ["-strip", "-quality", "70", "-tile", "1x#{image_paths.length}", "-geometry", "+0+0", to_path]
MiniMagick::Tool::Montage.new{|m| m.merge! montage_commond}
to_path
end
def self.compress(image_path, watermark = false)
to_path = "#{tmp_dir}/compress_#{SecureRandom.uuid.to_s.strip}.jpeg"
image = MiniMagick::Image.open image_path
image.combine_options do |b|
b.strip
b.quality "60"
end
if watermark
watermark_image = MiniMagick::Image.open("#{Rails.root}/app/assets/images/special_watermark.png")
watermark_width = (image.width * 0.9).to_i
watermark_height = (watermark_image.height * (watermark_width / watermark_image.width.to_f)).to_i
watermark_image.resize "#{watermark_width}x#{watermark_height}"
image = image.composite(watermark_image) do |c|
c.gravity 'center'
end
end
image.write to_path
to_path
end
end
图片合并
image_paths = files.map{|f| f.tempfile.path}
composite_path = ImageService.composite(image_paths)
File.open(composite_path) do |f|
attachment.path = f
end
文件格式大小限制
def create_company_change
files = params[:file_path]
flag, flash[:msg] = check_file(files)
unless flag
redirect_to my_whmall_account_informations_url and return
else
#todo
end
end
def check_file(files)
max_size = 1024 * 1024 * 3 #3M
file_type = ['image/gif ', 'image/png', 'image/jpeg', 'application/pdf']
return false, '上传文件不能为空' if files.blank?
files.each do |file|
return false, '文件不能大于3M' if file.size > max_size
return false, '可上传的图片格式将限于jpg、gif、png和pdf' unless file_type.include? file.content_type
end
return true, '变更申请提交成功,请等待审核。'
end
分享到:
相关推荐
使用它添加到您的Gemfile gem 'mojo_magick'在您的ruby代码中要求它require 'mojo_magick'去镇上! 查看几个简单的例子图像调整大小获取图像的大小(假设图像为“ 120wx222h”) dimensions = MojoMagick::get_image...
自述文件 该自述文件通常会记录启动和运行应用程序所需的所有步骤。 您可能要讲的内容: Ruby版本 系统依赖 配置 数据库创建 数据库初始化 如何运行测试套件 服务(作业队列,缓存服务器,搜索引擎等) ...
Pascal Magick Image Process
MiniMagick - ImageMagick或GraphicsMagick命令行的一个ruby封装
将此行添加到应用程序的 Gemfile 中: gem 'simple_magick' 然后执行: $ bundle 支持的版本 Ruby 2.0.0 或更高版本 用法 require 'simple_magick' if SimpleMagick . imagemagick_installed? image = ...
linux下采用开源库Magick++实现图片合成,图片添加中英文字体:需要自己下载编译Magick++,如下为部分代码,下载可看完整代码 #include <Magick++.h> #include <Magick++/Image.h> #include <Magick++/Drawable.h> ...
例子# Import thingsfrom breakpoint_magick import GetVSCodeBreakpoints# Get a list with VS Code breakpointsbreak_point_list = GetVSCodeBreakpoints ()# Example of processing to new formatprint ( "# ...
Magick.NET类库,.net平台操作图片
将此行添加到应用程序的 Gemfile 中: group :development , :test do gem 'dummy_magick' end 然后执行: $ bundle 用法 ## # Generate a dummy image file # # @param width [Integer] The width of the ...
图片处理 图片压缩 图片水印 高质量图片
这是一个非常简单的格式转换代码,可以把.PDF文件转换为.JPG文件,代码要起作用,服务器必须要安装Image Magick 扩展。 $pdf_file = './pdf/demo.pdf'; $save_to = './jpg/demo.jpg'; //make sure that apache has ...
.NET 将PDF转换为图片Demo 亲测可用 使用Magick.NET,使用...注:本Demo 是将PDF按页数转换为多张图片(可转换其中某页,最后一页或者第一页需要自己更改代码),不是转换成一张图片(此类需求的勿浪费资源下载,谢谢)
magick_path /usr/bin param_file params_JSins.csv wroi_file rois_JSins.nii.gz roi_file '' roiinfo_file rois_JSins.csv coregmat_file /INPUTS/coreg_mat.txt \ deffwd_file /INPUTS/y_deffwd.nii.gz \ ct1_...
可用的C#版 Magick.NET(dll),此版本包含通过加载图片后获取到64位的图片签名。可用于对图片进行完整的比对,对于需要开发图片库的伙伴有福了。
Magick++使用教程
ImageMagick的.NET库:Magick.NET ImageMagick是功能强大的图像处理库,支持超过(不包括子格式)。 使用Magick.NET,您可以在C#/ VB.NET / .NET Core应用程序中使用ImageMagick,而不必在服务器或台式机上安装...
勇敢的一个简单的图像大小调整器,可将图像转换为不同的分辨率并将其推... require "mini_magick"require "aws-sdk"require "uri"require "yaml" 现在要使用双色宝石,可以通过以下方式将宝石添加到您的项目中 require
Magick.NET图像操作库 包含 64与32 位
rtesseract, 用于超立方体识别的ruby 库 rtesseract 用于超立方体识别的ruby 库。要求:要正常工作,需要使用 rtesseract:超正方体- 程序ImageMagick - 程序RMagick或者 mini_magick -
大多数情况下,都是围绕magick函数进行包装。 安装 # Install the development version from GitHub: # install.packages("devtools") devtools :: install_github( " sctyner/memer " ) 可用模因 library( memer )...