Skip to content

Instantly share code, notes, and snippets.

@umate
Last active December 3, 2023 03:05
Show Gist options
  • Save umate/7588344 to your computer and use it in GitHub Desktop.
Save umate/7588344 to your computer and use it in GitHub Desktop.
CarrierWave gaussian blur filter using MiniMagick
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
version :blurred do
process :blur
end
def blur(radius=16)
manipulate! do |img|
original_path = img.path
temp_image_path = File.join(Rails.root, 'public', cache_dir, "/blurred_#{File.basename(original_path)}")
command = "convert #{original_path} -blur 0x#{radius} #{temp_image_path}"
system(command)
MiniMagick::Image.open(temp_image_path)
end
end
end
@StanlyShauro
Copy link

StanlyShauro commented Dec 3, 2023

to delete /tmp/blurred_....
replace

MiniMagick::Image.open(temp_image_path)

with

file = MiniMagick::Image.open(temp_image_path)
File.delete temp_image_path
file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment