diff options
| author | AppleDash <[email protected]> | 2020-08-07 19:27:33 -0400 |
|---|---|---|
| committer | AppleDash <[email protected]> | 2020-08-07 19:27:33 -0400 |
| commit | 07c9e6fcf2ae7b0e22c2333ebb3ffe6a5e3a1d3c (patch) | |
| tree | bec48d0f2665921e62d5fb17deacc439305ac1b6 /lib/booru/image_processing/processor.rb | |
| parent | 32a3f9346b8b39ab5b506019629fb416c86f2228 (diff) | |
Rewrite image processing engine pretty majorly
Diffstat (limited to 'lib/booru/image_processing/processor.rb')
| -rw-r--r-- | lib/booru/image_processing/processor.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/booru/image_processing/processor.rb b/lib/booru/image_processing/processor.rb new file mode 100644 index 0000000..e610b3e --- /dev/null +++ b/lib/booru/image_processing/processor.rb @@ -0,0 +1,55 @@ +module Booru + module ImageProcessing + class Processor + PROCESSORS = { + 'image/png' => Booru::ImageProcessing::PngProcessor, + 'image/jpeg' => Booru::ImageProcessing::JpegProcessor, + 'image/gif' => Booru::ImageProcessing::GifProcessor + } + + attr_reader :rasterized + + def initialize(original_path, directory) + @original_path = original_path + @directory = directory + @rasterized = original_path + end + + # Apply pre-processing to the image. This is anything that should be done to the original + # file, before any of the versions are generated. (eg: sanitization) + def pre_process + # do nothing by default + end + + # generate a version of the image with the given dimensions, and + # write it out to the given path. + def generate_version(dimensions, destination_path) + # you should do something here + raise NotImplementedError + end + + def generate_full_version(destination_path) + FileUtils.ln_sf(@original_path, destination_path) + end + + # special case processing for eg: WebM to gif conversion. + def additional_process + # do nothing + end + + # Apply post-processing to the image. This is anything that should be done to the original + # file, after all of the versions are generated. (eg: lossless compression) + def post_process + # do nothing by default + end + + def is_video? + false + end + + def self.for_content_type(content_type) + PROCESSORS[content_type] + end + end + end +end |
