Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unprocessed_image.rb « uploaders « app - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6dad5f602b6e92dd4a21249cf5a22ffe4072ad57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class UnprocessedImage < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  attr_accessor :strip_exif

  def strip_exif
    @strip_exif || false
  end

  def store_dir
    "uploads/images"
  end

  def extension_allowlist
    %w[jpg jpeg png gif]
  end

  def filename
    model.random_string + File.extname(@filename) if @filename
  end

  process :basic_process

  def basic_process
    manipulate! do |img|
      img.auto_orient
      img.strip if strip_exif
      img = yield(img) if block_given?
      img
    end
  end

  version :thumb_small
  version :thumb_medium
  version :thumb_large
  version :scaled_full do
    process :get_version_dimensions
  end

  def get_version_dimensions
    model.width, model.height = `identify -format "%wx%h " #{file.path}`.split(/x/)
  end
end