Class: Alchemy::EssencePicture

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Picture::Transformations
Defined in:
app/models/alchemy/essence_picture.rb

Instance Method Summary collapse

Methods included from Picture::Transformations

#can_be_cropped_to, #crop, #crop_size?, #default_mask, #image_size, #landscape_format?, #portrait_format?, #render_size?, #resize, #sizes_from_string, #square_format?, #thumbnail_size

Instance Method Details

#allow_image_cropping?(options = {}) ⇒ Boolean

Show image cropping link for content and options?

Returns:

  • (Boolean)


88
89
90
91
92
93
94
# File 'app/models/alchemy/essence_picture.rb', line 88

def allow_image_cropping?(options = {})
  content && content.settings_value(:crop, options) && picture &&
    picture.can_be_cropped_to(
      content.settings_value(:image_size, options),
      content.settings_value(:upsample, options)
    )
end

#cropping_maskObject

A Hash of coordinates suitable for the graphical image cropper.



74
75
76
77
78
79
80
# File 'app/models/alchemy/essence_picture.rb', line 74

def cropping_mask
  return if crop_from.blank? || crop_size.blank?
  crop_from = point_from_string(read_attribute(:crop_from))
  crop_size = sizes_from_string(read_attribute(:crop_size))

  point_and_mask_to_points(crop_from, crop_size)
end

#picture_url(options = {}) ⇒ Object

The url to show the picture.

Takes all values like name and crop sizes (crop_from, crop_size from the build in graphical image cropper) and also adds the security token.

You typically want to set the size the picture should be resized to.

Example:

essence_picture.picture_url(size: '200x300', crop: true, format: 'gif')
# '/pictures/1/show/200x300/crop/cats.gif?sh=765rfghj'

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • size (String)

    The size the picture should be resized to.

  • format (String)

    The format the picture should be rendered in. Defaults to the image_output_format from the Alchemy::Config.

  • crop (Boolean)

    If set to true the picture will be cropped to fit the size value.



57
58
59
60
# File 'app/models/alchemy/essence_picture.rb', line 57

def picture_url(options = {})
  return if picture.nil?
  routes.show_picture_path(picture_params(options))
end

#preview_text(max = 30) ⇒ Object

The name of the picture used as preview text in element editor views.

Parameters:

  • max (Integer) (defaults to: 30)

    The maximum length of the text returned.



67
68
69
70
# File 'app/models/alchemy/essence_picture.rb', line 67

def preview_text(max = 30)
  return "" if picture.nil?
  picture.name.to_s[0..max - 1]
end

#serialized_ingredientObject

Returns a serialized ingredient value for json api



83
84
85
# File 'app/models/alchemy/essence_picture.rb', line 83

def serialized_ingredient
  picture_url(content.settings)
end