Class: Alchemy::PictureThumb

Inherits:
BaseRecord
  • Object
show all
Defined in:
app/models/alchemy/picture_thumb.rb,
app/models/alchemy/picture_thumb/uid.rb,
app/models/alchemy/picture_thumb/create.rb,
app/models/alchemy/picture_thumb/signature.rb

Overview

The persisted version of a rendered picture variant

You can configure the generator class to implement a different thumbnail store (ie. a remote file storage).

config/initializers/alchemy.rb
Alchemy::PictureThumb.generator_class = My::ThumbnailGenerator

Defined Under Namespace

Classes: Create, Signature, Uid

Class Method Summary collapse

Class Method Details

.generate_thumbs!(picture) ⇒ Object

Upfront generation of picture thumbnails

Called after a Alchemy::Picture has been created (after an image has been uploaded)

Generates three types of thumbnails that are used by Alchemys picture archive and persists them in the configures file store (Default Dragonfly::FileDataStore).


41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/alchemy/picture_thumb.rb', line 41

def generate_thumbs!(picture)
  Alchemy::Picture::THUMBNAIL_SIZES.values.each do |size|
    variant = Alchemy::PictureVariant.new(picture, {
      size: size,
      flatten: true,
    })
    signature = Alchemy::PictureThumb::Signature.call(variant)
    thumb = find_by(signature: signature)
    next if thumb

    uid = Alchemy::PictureThumb::Uid.call(signature, variant)
    generator_class.call(variant, signature, uid)
  end
end

.generator_classObject

Thumbnail generator class

See Also:


22
23
24
# File 'app/models/alchemy/picture_thumb.rb', line 22

def generator_class
  @_generator_class ||= Alchemy::PictureThumb::Create
end

.generator_class=(klass) ⇒ Object

Set a thumbnail generator class

See Also:


29
30
31
# File 'app/models/alchemy/picture_thumb.rb', line 29

def generator_class=(klass)
  @_generator_class = klass
end