Sha256: 5020c3e80a0339c8a7cb10180d20cae70e8dea448fc20434cd1c6c57c00eb15f

Contents?: true

Size: 1.75 KB

Versions: 16

Compression:

Stored size: 1.75 KB

Contents

module Ti
  class Dphoto < ActiveRecord::Base
    belongs_to :doc
    mount_uploader :image, DphotoUploader

    # в ~ от размеров thumb-ов и page_content_width - выдать соответствующую картинку
    # • Если у картинки thumb_big шириной ≥ page_content_width - вставляем этот thumb_big.
    # • Иначе: вставлем thumb_small.
    def content_image(type='normal')

      if type == 'normal'
        img = MiniMagick::Image.open(image.thumb_big.path)
        w = SiteProp.first.page_content_width
        if img['width'] < w
          image.thumb_small
        else
          image.thumb_big
        end

      elsif type == 'small'
        image.thumb_small

      elsif type == 'big'
        image.thumb_big
      end

    end

    # выдать размеры картинки, которая будет вставлена в текст страницы
    def content_image_size(type='normal')

      if type == 'normal'
        img = MiniMagick::Image.open(image.thumb_big.path)
        w = SiteProp.first.page_content_width
        if img['width'] < w
          img = MiniMagick::Image.open(image.thumb_small.path)
          [img['width'], img['height']]
        else
          [img['width'], img['height']]
        end

      elsif type == 'small'
        img = MiniMagick::Image.open(image.thumb_small.path)
        [img['width'], img['height']]

      elsif type == 'big'
        img = MiniMagick::Image.open(image.thumb_big.path)
        [img['width'], img['height']]
      end
    end

    # выдать размеры картинки thumb_preview
    def thumb_preview_size
      img = MiniMagick::Image.open(image.thumb_preview.path)
      [img['width'], img['height']]
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
c80_yax-0.1.0.25 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.24 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.23 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.22 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.21 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.20 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.18 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.17 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.16 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.15 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.14 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.13 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.12 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.11 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.10 engines/ti/app/models/ti/dphoto.rb
c80_yax-0.1.0.9 engines/ti/app/models/ti/dphoto.rb