Skip to content
This repository

MediaMagick aims to make dealing with multimedia resources a very easy task – like magic. Supports mongoid.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 config
Octocat-spinner-32 gemfiles
Octocat-spinner-32 lib
Octocat-spinner-32 script
Octocat-spinner-32 spec
Octocat-spinner-32 tmp
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 CHANGELOG.md
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Guardfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 media_magick.gemspec
README.md

MediaMagick Build Status Build Status Code Climate

MediaMagick aims to make dealing with multimedia resources a very easy task – like magic. It wraps up robust solutions for upload, associate and display images, videos, audios and files to any model in your rails app.

Installation

Add this line to your application's Gemfile:

gem 'media_magick', '~> 0.4.0'

And then execute:

$ bundle

Getting Started

Assets

Add these lines after //= require jquery in app/assets/javascripts/application.js:

//= require media_magick/plupload_it
//= require media_magick/toggleSortable

Model

class Album
  include Mongoid::Document
  include MediaMagick::Model

  attaches_many :photos, type: :image
end

Controller

def new
  @album = Album.new
end

View

<%= attachment_uploader(@album, :photos, :image) %>
<%= attachment_loader(@album, :photos) %>

Javascript

$(document).ready(function () {
  $(".attachmentUploader").pluploadIt();
});

Allow Videos (youtube/vimeo)

class Album
  include Mongoid::Document
  include MediaMagick::Model

  attaches_many :photos, type: :image, allow_videos: true
end
<%= attachment_uploader(@album, :photos, :video) %>
<%= attachment_uploader(@album, :photos, :image) %>
<%= attachment_loader(@album, :photos) %>

Configuring

Model

class Album
  include Mongoid::Document
  include MediaMagick::Model

  attaches_many :photos, type: 'image'
end

album = Album.create
album.photos.create(photo: params[:file])
album.reload.photos.first.url
album.reload.photos.first.filename

attaches One

class Album
  include Mongoid::Document
  include MediaMagick::Model

  attaches_one :photo, type: 'image'
end

album = Album.create
album.photo.create(photo: params[:file])
album.reload.photo.url
album.reload.photo.filename

Custom classes

class Album
  include Mongoid::Document
  include MediaMagick::Model

  attaches_many :photos, type: 'image' do
    field :tags, type: Array
  end
end

album = Album.create
album.photos.create(photo: params[:file], tags: ['ruby', 'guru'])
album.reload.photos.first.tags #=> ['ruby', 'guru']

Custom uploader

Media Magick only supports mini_magick. https://github.com/minimagick/minimagick

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

  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  version :thumb do
    process :resize_to_fit => [156, 156]
  end
end
class Album
  include Mongoid::Document
  include MediaMagick::Model

  attaches_many :photos, type: 'image', uploader: PhotoUploader
end

album = Album.create
album.photos.create(photo: params[:file])
album.reload.photos.first.thumb.url

Form View

coming soon

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

MIT License

Something went wrong with that request. Please try again.