carrierwave-pressplane 0.5.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/README.md +748 -0
  2. data/lib/carrierwave.rb +116 -0
  3. data/lib/carrierwave/compatibility/paperclip.rb +95 -0
  4. data/lib/carrierwave/locale/en.yml +9 -0
  5. data/lib/carrierwave/mount.rb +382 -0
  6. data/lib/carrierwave/orm/activerecord.rb +46 -0
  7. data/lib/carrierwave/processing/mime_types.rb +58 -0
  8. data/lib/carrierwave/processing/mini_magick.rb +252 -0
  9. data/lib/carrierwave/processing/rmagick.rb +279 -0
  10. data/lib/carrierwave/sanitized_file.rb +315 -0
  11. data/lib/carrierwave/storage/abstract.rb +30 -0
  12. data/lib/carrierwave/storage/cloud_files.rb +188 -0
  13. data/lib/carrierwave/storage/file.rb +56 -0
  14. data/lib/carrierwave/storage/fog.rb +333 -0
  15. data/lib/carrierwave/storage/right_s3.rb +1 -0
  16. data/lib/carrierwave/storage/s3.rb +240 -0
  17. data/lib/carrierwave/test/matchers.rb +241 -0
  18. data/lib/carrierwave/uploader.rb +44 -0
  19. data/lib/carrierwave/uploader/cache.rb +178 -0
  20. data/lib/carrierwave/uploader/callbacks.rb +35 -0
  21. data/lib/carrierwave/uploader/configuration.rb +168 -0
  22. data/lib/carrierwave/uploader/default_url.rb +19 -0
  23. data/lib/carrierwave/uploader/download.rb +75 -0
  24. data/lib/carrierwave/uploader/extension_whitelist.rb +49 -0
  25. data/lib/carrierwave/uploader/mountable.rb +39 -0
  26. data/lib/carrierwave/uploader/processing.rb +90 -0
  27. data/lib/carrierwave/uploader/proxy.rb +77 -0
  28. data/lib/carrierwave/uploader/remove.rb +23 -0
  29. data/lib/carrierwave/uploader/store.rb +113 -0
  30. data/lib/carrierwave/uploader/url.rb +47 -0
  31. data/lib/carrierwave/uploader/versions.rb +237 -0
  32. data/lib/carrierwave/validations/active_model.rb +64 -0
  33. data/lib/carrierwave/version.rb +3 -0
  34. data/lib/generators/templates/uploader.rb +48 -0
  35. data/lib/generators/uploader_generator.rb +7 -0
  36. metadata +215 -0
data/README.md ADDED
@@ -0,0 +1,748 @@
1
+ # CarrierWave
2
+
3
+ This gem provides a simple and extremely flexible way to upload files from Ruby applications.
4
+ It works well with Rack based web applications, such as Ruby on Rails.
5
+
6
+ [![Build Status](https://secure.travis-ci.org/jnicklas/carrierwave.png)](http://travis-ci.org/jnicklas/carrierwave)
7
+
8
+ ## Information
9
+
10
+ * RDoc documentation [available on RubyDoc.info](http://rubydoc.info/gems/carrierwave/frames)
11
+ * Source code [available on GitHub](http://github.com/jnicklas/carrierwave)
12
+ * More information, known limitations, and how-tos [available on the wiki](https://github.com/jnicklas/carrierwave/wiki)
13
+
14
+ ## Getting Help
15
+
16
+ * Please ask the [Google Group](http://groups.google.com/group/carrierwave) for help if you have any questions.
17
+ * Please report bugs on the [issue tracker](http://github.com/jnicklas/carrierwave/issues) but read the "getting help" section in the wiki first.
18
+
19
+ ## Installation
20
+
21
+ Install the latest stable release:
22
+
23
+ [sudo] gem install carrierwave
24
+
25
+ In Rails, add it to your Gemfile:
26
+
27
+ ``` ruby
28
+ gem 'carrierwave'
29
+ ```
30
+
31
+ Note that CarrierWave is not compatible with Rails 2 as of version 0.5. If you want to use
32
+ Rails 2, please use the 0.4-stable branch on GitHub.
33
+
34
+ ## Getting Started
35
+
36
+ Start off by generating an uploader:
37
+
38
+ rails generate uploader Avatar
39
+
40
+ this should give you a file in:
41
+
42
+ app/uploaders/avatar_uploader.rb
43
+
44
+ Check out this file for some hints on how you can customize your uploader. It
45
+ should look something like this:
46
+
47
+ ``` ruby
48
+ class AvatarUploader < CarrierWave::Uploader::Base
49
+ storage :file
50
+ end
51
+ ```
52
+
53
+ You can use your uploader class to store and retrieve files like this:
54
+
55
+ ``` ruby
56
+ uploader = AvatarUploader.new
57
+
58
+ uploader.store!(my_file)
59
+
60
+ uploader.retrieve_from_store!('my_file.png')
61
+ ```
62
+
63
+ CarrierWave gives you a `store` for permanent storage, and a `cache` for
64
+ temporary storage. You can use different stores, including filesystem
65
+ and cloud storage.
66
+
67
+ Most of the time you are going to want to use CarrierWave together with an ORM.
68
+ It is quite simple to mount uploaders on columns in your model, so you can
69
+ simply assign files and get going:
70
+
71
+ ### ActiveRecord
72
+
73
+ Make sure you are loading CarrierWave after loading your ORM, otherwise you'll
74
+ need to require the relevant extension manually, e.g.:
75
+
76
+ ``` ruby
77
+ require 'carrierwave/orm/activerecord'
78
+ ```
79
+
80
+ Add a string column to the model you want to mount the uploader on:
81
+
82
+ ``` ruby
83
+ add_column :users, :avatar, :string
84
+ ```
85
+
86
+ Open your model file and mount the uploader:
87
+
88
+ ``` ruby
89
+ class User < ActiveRecord::Base
90
+ mount_uploader :avatar, AvatarUploader
91
+ end
92
+ ```
93
+
94
+ Now you can cache files by assigning them to the attribute, they will
95
+ automatically be stored when the record is saved.
96
+
97
+ ``` ruby
98
+ u = User.new
99
+ u.avatar = params[:file]
100
+ u.avatar = File.open('somewhere')
101
+ u.save!
102
+ u.avatar.url # => '/url/to/file.png'
103
+ u.avatar.current_path # => 'path/to/file.png'
104
+ u.avatar_identifier # => 'file.png'
105
+ ```
106
+
107
+ ### DataMapper, Mongoid, Sequel
108
+
109
+ Other ORM support has been extracted into separate gems:
110
+
111
+ * [carrierwave-datamapper](https://github.com/jnicklas/carrierwave-datamapper)
112
+ * [carrierwave-mongoid](https://github.com/jnicklas/carrierwave-mongoid)
113
+ * [carrierwave-sequel](https://github.com/jnicklas/carrierwave-sequel)
114
+
115
+ There are more extensions listed in [the wiki](https://github.com/jnicklas/carrierwave/wiki)
116
+
117
+ ## Changing the storage directory
118
+
119
+ In order to change where uploaded files are put, just override the `store_dir`
120
+ method:
121
+
122
+ ``` ruby
123
+ class MyUploader < CarrierWave::Uploader::Base
124
+ def store_dir
125
+ 'public/my/upload/directory'
126
+ end
127
+ end
128
+ ```
129
+
130
+ This works for the file storage as well as Amazon S3 and Rackspace Cloud Files.
131
+ Define `store_dir` as `nil` if you'd like to store files at the root level.
132
+
133
+ ## Securing uploads
134
+
135
+ Certain file might be dangerous if uploaded to the wrong location, such as php
136
+ files or other script files. CarrierWave allows you to specify a white-list of
137
+ allowed extensions.
138
+
139
+ If you're mounting the uploader, uploading a file with the wrong extension will
140
+ make the record invalid instead. Otherwise, an error is raised.
141
+
142
+ ``` ruby
143
+ class MyUploader < CarrierWave::Uploader::Base
144
+ def extension_white_list
145
+ %w(jpg jpeg gif png)
146
+ end
147
+ end
148
+ ```
149
+
150
+ ### Filenames and unicode chars
151
+
152
+ Another security issue you should care for is the file names (see
153
+ [Ruby On Rails Security Guide](http://guides.rubyonrails.org/security.html#file-uploads)).
154
+ By default, CarrierWave provides only English letters, arabic numerals and '-+_.' symbols as
155
+ white-listed characters in the file name. If you want to support local scripts (Cyrillic letters, letters with diacritics and so on), you
156
+ have to override `sanitize_regexp` method. It should return regular expression which would match
157
+ all *non*-allowed symbols.
158
+
159
+ With Ruby 1.9 and higher you can simply write (as it has [Oniguruma](http://oniguruma.rubyforge.org/oniguruma/)
160
+ built-in):
161
+
162
+ ``` ruby
163
+ CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/
164
+ ```
165
+
166
+ With Ruby 1.8 you have to manually specify all character ranges. For example, for files which may
167
+ contain Russian letters:
168
+
169
+ ``` ruby
170
+ CarrierWave::SanitizedFile.sanitize_regexp = /[^a-zA-Zа-яА-ЯёЁ0-9\.\-\+_]/u
171
+ ```
172
+
173
+ Also make sure that allowing non-latin characters won't cause a compatibility issue with a third-party
174
+ plugins or client-side software.
175
+
176
+ ## Setting the content type
177
+
178
+ If you care about the content type of your files and notice that it's not being set
179
+ as expected, you can configure your uploaders to use `CarrierWave::MimeTypes`.
180
+ This adds a dependency on the [mime-types](http://rubygems.org/gems/mime-types) gem,
181
+ but is recommended when using fog, and fog already has a dependency on mime-types.
182
+
183
+ ``` ruby
184
+ require 'carrierwave/processing/mime_types'
185
+
186
+ class MyUploader < CarrierWave::Uploader::Base
187
+ include CarrierWave::MimeTypes
188
+
189
+ process :set_content_type
190
+ end
191
+ ```
192
+
193
+ ## Adding versions
194
+
195
+ Often you'll want to add different versions of the same file. The classic
196
+ example is image thumbnails. There is built in support for this:
197
+
198
+ ``` ruby
199
+ class MyUploader < CarrierWave::Uploader::Base
200
+ include CarrierWave::RMagick
201
+
202
+ process :resize_to_fit => [800, 800]
203
+
204
+ version :thumb do
205
+ process :resize_to_fill => [200,200]
206
+ end
207
+
208
+ end
209
+ ```
210
+
211
+ When this uploader is used, an uploaded image would be scaled to be no larger
212
+ than 800 by 800 pixels. A version called thumb is then created, which is scaled
213
+ and cropped to exactly 200 by 200 pixels. The uploader could be used like this:
214
+
215
+ ``` ruby
216
+ uploader = AvatarUploader.new
217
+ uploader.store!(my_file) # size: 1024x768
218
+
219
+ uploader.url # => '/url/to/my_file.png' # size: 800x600
220
+ uploader.thumb.url # => '/url/to/thumb_my_file.png' # size: 200x200
221
+ ```
222
+
223
+ One important thing to remember is that process is called *before* versions are
224
+ created. This can cut down on processing cost.
225
+
226
+ It is possible to nest versions within versions:
227
+
228
+ ``` ruby
229
+ class MyUploader < CarrierWave::Uploader::Base
230
+
231
+ version :animal do
232
+ version :human
233
+ version :monkey
234
+ version :llama
235
+ end
236
+ end
237
+ ```
238
+
239
+ ### Conditional versions
240
+
241
+ Occasionally you want to restrict the creation of versions on certain
242
+ properties within the model or based on the picture itself.
243
+
244
+ ``` ruby
245
+ class MyUploader < CarrierWave::Uploader::Base
246
+
247
+ version :human, :if => :is_human?
248
+ version :monkey, :if => :is_monkey?
249
+ version :banner, :if => :is_landscape?
250
+
251
+ protected
252
+
253
+ def is_human? picture
254
+ model.can_program?(:ruby)
255
+ end
256
+
257
+ def is_monkey? picture
258
+ model.favorite_food == 'banana'
259
+ end
260
+
261
+ def is_landscape? picture
262
+ image = MiniMagick::Image.open(picture.path)
263
+ image[:width] > image[:height]
264
+ end
265
+
266
+ end
267
+ ```
268
+
269
+ The `model` variable points to the instance object the uploader is attached to.
270
+
271
+ ## Making uploads work across form redisplays
272
+
273
+ Often you'll notice that uploaded files disappear when a validation fails.
274
+ CarrierWave has a feature that makes it easy to remember the uploaded file even
275
+ in that case. Suppose your `user` model has an uploader mounted on `avatar`
276
+ file, just add a hidden field called `avatar_cache`. In Rails, this would look
277
+ like this:
278
+
279
+ ``` erb
280
+ <%= form_for @user, :html => {:multipart => true} do |f| %>
281
+ <p>
282
+ <label>My Avatar</label>
283
+ <%= f.file_field :avatar %>
284
+ <%= f.hidden_field :avatar_cache %>
285
+ </p>
286
+ <% end %>
287
+ ````
288
+
289
+ It might be a good idea to show the user that a file has been uploaded, in the
290
+ case of images, a small thumbnail would be a good indicator:
291
+
292
+ ``` erb
293
+ <%= form_for @user, :html => {:multipart => true} do |f| %>
294
+ <p>
295
+ <label>My Avatar</label>
296
+ <%= image_tag(@user.avatar_url) if @user.avatar? %>
297
+ <%= f.file_field :avatar %>
298
+ <%= f.hidden_field :avatar_cache %>
299
+ </p>
300
+ <% end %>
301
+ ```
302
+
303
+ ## Removing uploaded files
304
+
305
+ If you want to remove a previously uploaded file on a mounted uploader, you can
306
+ easily add a checkbox to the form which will remove the file when checked.
307
+
308
+ ``` erb
309
+ <%= form_for @user, :html => {:multipart => true} do |f| %>
310
+ <p>
311
+ <label>My Avatar</label>
312
+ <%= image_tag(@user.avatar_url) if @user.avatar? %>
313
+ <%= f.file_field :avatar %>
314
+ </p>
315
+
316
+ <p>
317
+ <label>
318
+ <%= f.check_box :remove_avatar %>
319
+ Remove avatar
320
+ </label>
321
+ </p>
322
+ <% end %>
323
+ ```
324
+
325
+ If you want to remove the file manually, you can call <code>remove_avatar!</code>.
326
+
327
+ ## Uploading files from a remote location
328
+
329
+ Your users may find it convenient to upload a file from a location on the Internet
330
+ via a URL. CarrierWave makes this simple, just add the appropriate attribute to your
331
+ form and you're good to go:
332
+
333
+ ``` erb
334
+ <%= form_for @user, :html => {:multipart => true} do |f| %>
335
+ <p>
336
+ <label>My Avatar URL:</label>
337
+ <%= image_tag(@user.avatar_url) if @user.avatar? %>
338
+ <%= f.text_field :remote_avatar_url %>
339
+ </p>
340
+ <% end %>
341
+ ```
342
+
343
+ ## Providing a default URL
344
+
345
+ In many cases, especially when working with images, it might be a good idea to
346
+ provide a default url, a fallback in case no file has been uploaded. You can do
347
+ this easily by overriding the `default_url` method in your uploader:
348
+
349
+ ``` ruby
350
+ class MyUploader < CarrierWave::Uploader::Base
351
+ def default_url
352
+ "/images/fallback/" + [version_name, "default.png"].compact.join('_')
353
+ end
354
+ end
355
+ ```
356
+
357
+ ## Recreating versions
358
+
359
+ You might come to a situation where you want to retroactively change a version
360
+ or add a new one. You can use the recreate_versions! method to recreate the
361
+ versions from the base file. This uses a naive approach which will re-upload and
362
+ process all versions.
363
+
364
+ ``` ruby
365
+ instance = MyUploader.new
366
+ instance.recreate_versions!
367
+ ```
368
+
369
+ Or on a mounted uploader:
370
+
371
+ ``` ruby
372
+ User.all.each do |user|
373
+ user.avatar.recreate_versions!
374
+ end
375
+ ```
376
+
377
+ ## Configuring CarrierWave
378
+
379
+ CarrierWave has a broad range of configuration options, which you can configure,
380
+ both globally and on a per-uploader basis:
381
+
382
+ ``` ruby
383
+ CarrierWave.configure do |config|
384
+ config.permissions = 0666
385
+ config.storage = :s3
386
+ end
387
+ ```
388
+
389
+ Or alternatively:
390
+
391
+ ``` ruby
392
+ class AvatarUploader < CarrierWave::Uploader::Base
393
+ permissions 0777
394
+ end
395
+ ```
396
+
397
+ If you're using Rails, create an initializer for this:
398
+
399
+ ``` ruby
400
+ config/initializers/carrierwave.rb
401
+ ```
402
+
403
+ ## Testing with CarrierWave
404
+
405
+ It's a good idea to test you uploaders in isolation. In order to speed up your
406
+ tests, it's recommended to switch off processing in your tests, and to use the
407
+ file storage. In Rails you could do that by adding an initializer with:
408
+
409
+ ``` ruby
410
+ if Rails.env.test? or Rails.env.cucumber?
411
+ CarrierWave.configure do |config|
412
+ config.storage = :file
413
+ config.enable_processing = false
414
+ end
415
+ end
416
+ ```
417
+
418
+ If you need to test your processing, you should test it in isolation, and enable
419
+ processing only for those tests that need it.
420
+
421
+ CarrierWave comes with some RSpec matchers which you may find useful:
422
+
423
+ ``` ruby
424
+ require 'carrierwave/test/matchers'
425
+
426
+ describe MyUploader do
427
+ include CarrierWave::Test::Matchers
428
+
429
+ before do
430
+ MyUploader.enable_processing = true
431
+ @uploader = MyUploader.new(@user, :avatar)
432
+ @uploader.store!(File.open(path_to_file))
433
+ end
434
+
435
+ after do
436
+ MyUploader.enable_processing = false
437
+ end
438
+
439
+ context 'the thumb version' do
440
+ it "should scale down a landscape image to be exactly 64 by 64 pixels" do
441
+ @uploader.thumb.should have_dimensions(64, 64)
442
+ end
443
+ end
444
+
445
+ context 'the small version' do
446
+ it "should scale down a landscape image to fit within 200 by 200 pixels" do
447
+ @uploader.small.should be_no_larger_than(200, 200)
448
+ end
449
+ end
450
+
451
+ it "should make the image readable only to the owner and not executable" do
452
+ @uploader.should have_permissions(0600)
453
+ end
454
+ end
455
+ ```
456
+
457
+ Setting the enable_processing flag on an uploader will prevent any of the versions from processing as well.
458
+ Processing can be enabled for a single version by setting the processing flag on the version like so:
459
+
460
+ ``` ruby
461
+ @uploader.thumb.enable_processing = true
462
+ ```
463
+
464
+ ## Using Amazon S3
465
+
466
+ [Fog](http://github.com/geemus/fog) is used to support Amazon S3. Ensure you have it installed:
467
+
468
+ gem install fog
469
+
470
+ You'll need to provide your fog_credentials and a fog_directory (also known as a bucket) in an initializer.
471
+ For the sake of performance it is assumed that the directory already exists, so please create it if need be.
472
+ You can also pass in additional options, as documented fully in lib/carrierwave/storage/fog.rb. Here's a full example:
473
+
474
+ ``` ruby
475
+ CarrierWave.configure do |config|
476
+ config.fog_credentials = {
477
+ :provider => 'AWS', # required
478
+ :aws_access_key_id => 'xxx', # required
479
+ :aws_secret_access_key => 'yyy', # required
480
+ :region => 'eu-west-1' # optional, defaults to 'us-east-1'
481
+ }
482
+ config.fog_directory = 'name_of_directory' # required
483
+ config.fog_host = 'https://assets.example.com' # optional, defaults to nil
484
+ config.fog_public = false # optional, defaults to true
485
+ config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
486
+ end
487
+ ```
488
+
489
+ In your uploader, set the storage to :fog
490
+
491
+ ``` ruby
492
+ class AvatarUploader < CarrierWave::Uploader::Base
493
+ storage :fog
494
+ end
495
+ ```
496
+
497
+ That's it! You can still use the `CarrierWave::Uploader#url` method to return the url to the file on Amazon S3.
498
+
499
+ ## Using Rackspace Cloud Files
500
+
501
+ [Fog](http://github.com/geemus/fog) is used to support Rackspace Cloud Files. Ensure you have it installed:
502
+
503
+ gem install fog
504
+
505
+ You'll need to configure a directory (also known as a container), username and API key in the initializer.
506
+ For the sake of performance it is assumed that the directory already exists, so please create it if need be.
507
+
508
+ ``` ruby
509
+ CarrierWave.configure do |config|
510
+ config.fog_credentials = {
511
+ :provider => 'Rackspace',
512
+ :rackspace_username => 'xxxxxx',
513
+ :rackspace_api_key => 'yyyyyy'
514
+ }
515
+ config.fog_directory = 'name_of_directory'
516
+ end
517
+ ```
518
+
519
+ You can optionally include your CDN host name in the configuration.
520
+ This is *highly* recommended, as without it every request requires a lookup
521
+ of this information.
522
+
523
+ ``` ruby
524
+ config.fog_host = "http://c000000.cdn.rackspacecloud.com"
525
+ ```
526
+
527
+ The UK Rackspace Cloud doesn’t have the same auth server as the US Cloud.
528
+ In case you are using Rackspace UK, you have to adjust the Auth URL:
529
+
530
+ ``` ruby
531
+ config.rackspace_auth_url = 'lon.auth.api.rackspacecloud.com'
532
+ ```
533
+
534
+ In your uploader, set the storage to :fog
535
+
536
+ ``` ruby
537
+ class AvatarUploader < CarrierWave::Uploader::Base
538
+ storage :fog
539
+ end
540
+ ```
541
+
542
+ That's it! You can still use the `CarrierWave::Uploader#url` method to return
543
+ the url to the file on Rackspace Cloud Files.
544
+
545
+ ## Using Google Storage for Developers
546
+
547
+ [Fog](http://github.com/geemus/fog) is used to support Google Storage for Developers. Ensure you have it installed:
548
+
549
+ gem install fog
550
+
551
+ You'll need to configure a directory (also known as a bucket), access key id and secret access key in the initializer.
552
+ For the sake of performance it is assumed that the directory already exists, so please create it if need be.
553
+
554
+ ``` ruby
555
+ CarrierWave.configure do |config|
556
+ config.fog_credentials = {
557
+ :provider => 'Google',
558
+ :google_storage_access_key_id => 'xxxxxx',
559
+ :google_storage_secret_access_key => 'yyyyyy'
560
+ }
561
+ config.fog_directory = 'name_of_directory'
562
+ end
563
+ ```
564
+
565
+ In your uploader, set the storage to :fog
566
+
567
+ ``` ruby
568
+ class AvatarUploader < CarrierWave::Uploader::Base
569
+ storage :fog
570
+ end
571
+ ```
572
+
573
+ That's it! You can still use the `CarrierWave::Uploader#url` method to return
574
+ the url to the file on Google.
575
+
576
+ ## Using RMagick
577
+
578
+ If you're uploading images, you'll probably want to manipulate them in some way,
579
+ you might want to create thumbnail images for example. CarrierWave comes with a
580
+ small library to make manipulating images with RMagick easier, you'll need to
581
+ include it in your Uploader:
582
+
583
+ ``` ruby
584
+ class AvatarUploader < CarrierWave::Uploader::Base
585
+ include CarrierWave::RMagick
586
+ end
587
+ ```
588
+
589
+ The RMagick module gives you a few methods, like
590
+ `CarrierWave::RMagick#resize_to_fill` which manipulate the image file in some
591
+ way. You can set a `process` callback, which will call that method any time a
592
+ file is uploaded.
593
+ There is a demonstration of convert here.
594
+ Convert will only work if the file has the same file extension, thus the use of the filename method.
595
+
596
+ ``` ruby
597
+ class AvatarUploader < CarrierWave::Uploader::Base
598
+ include CarrierWave::RMagick
599
+
600
+ process :resize_to_fill => [200, 200]
601
+ process :convert => 'png'
602
+
603
+ def filename
604
+ super.chomp(File.extname(super)) + '.png'
605
+ end
606
+ end
607
+ ```
608
+
609
+ Check out the manipulate! method, which makes it easy for you to write your own
610
+ manipulation methods.
611
+
612
+ ## Using MiniMagick
613
+
614
+ MiniMagick is similar to RMagick but performs all the operations using the 'mogrify'
615
+ command which is part of the standard ImageMagick kit. This allows you to have the power
616
+ of ImageMagick without having to worry about installing all the RMagick libraries.
617
+
618
+ See the MiniMagick site for more details:
619
+
620
+ http://github.com/probablycorey/mini_magick
621
+
622
+ And the ImageMagick command line options for more for whats on offer:
623
+
624
+ http://www.imagemagick.org/script/command-line-options.php
625
+
626
+ Currently, the MiniMagick carrierwave processor provides exactly the same methods as
627
+ for the RMagick processor.
628
+
629
+ ``` ruby
630
+ class AvatarUploader < CarrierWave::Uploader::Base
631
+ include CarrierWave::MiniMagick
632
+
633
+ process :resize_to_fill => [200, 200]
634
+ end
635
+ ```
636
+
637
+ ## Migrating from Paperclip
638
+
639
+ If you are using Paperclip, you can use the provided compatibility module:
640
+
641
+ ``` ruby
642
+ class AvatarUploader < CarrierWave::Uploader::Base
643
+ include CarrierWave::Compatibility::Paperclip
644
+ end
645
+ ```
646
+
647
+ See the documentation for `CarrierWave::Compatibility::Paperclip` for more
648
+ details.
649
+
650
+ Be sure to use mount_on to specify the correct column:
651
+
652
+ ``` ruby
653
+ mount_uploader :avatar, AvatarUploader, :mount_on => :avatar_file_name
654
+ ```
655
+
656
+ Unfortunately attachment_fu differs too much in philosophy for there to be a
657
+ sensible compatibility mode. Patches for migrating from other solutions will be
658
+ happily accepted.
659
+
660
+ ## i18n
661
+
662
+ The Active Record validations use the Rails i18n framework. Add these keys to
663
+ your translations file:
664
+
665
+ ``` yaml
666
+ errors:
667
+ messages:
668
+ carrierwave_processing_error: 'Cannot resize image.'
669
+ carrierwave_integrity_error: 'Not an image.'
670
+ ```
671
+
672
+ ## Large files
673
+
674
+ By default, CarrierWave copies an uploaded file twice, first copying the file into the cache, then
675
+ copying the file into the store. For large files, this can be prohibitively time consuming.
676
+
677
+ You may change this behavior by overriding either or both of the `move_to_cache` and
678
+ `move_to_store` methods:
679
+
680
+ ``` ruby
681
+ class MyUploader < CarrierWave::Uploader::Base
682
+ def move_to_cache
683
+ true
684
+ end
685
+ def move_to_store
686
+ true
687
+ end
688
+ end
689
+ ```
690
+
691
+ When the `move_to_cache` and/or `move_to_store` methods return true, files will be moved (instead of copied) to the cache and store respectively.
692
+
693
+ This has only been tested with the local filesystem store.
694
+
695
+ ## Contributing to CarrierWave
696
+
697
+ CarrierWave thrives on a large number of [contributors](https://github.com/jnicklas/carrierwave/contributors),
698
+ and pull requests are very welcome. Before submitting a pull request, please make sure that your changes are well tested.
699
+
700
+ You'll need to install bundler and the gem dependencies:
701
+
702
+ gem install bundler
703
+ bundle install
704
+
705
+ You should now be able to run the local tests:
706
+
707
+ bundle exec rake
708
+
709
+ You can also run the remote specs by creating a ~/.fog file:
710
+
711
+ ``` yaml
712
+ :carrierwave:
713
+ :aws_access_key_id: xxx
714
+ :aws_secret_access_key: yyy
715
+ :rackspace_username: xxx
716
+ :rackspace_api_key: yyy
717
+ :google_storage_access_key_id: xxx
718
+ :google_storage_secret_access_key: yyy
719
+ ```
720
+
721
+ You should now be able to run the remote tests:
722
+
723
+ REMOTE=true bundle exec rake
724
+
725
+ Please test with the latest Ruby 1.8.x and 1.9.x versions using RVM if possible.
726
+
727
+ ## License
728
+
729
+ Copyright (c) 2008 Jonas Nicklas
730
+
731
+ Permission is hereby granted, free of charge, to any person obtaining
732
+ a copy of this software and associated documentation files (the
733
+ "Software"), to deal in the Software without restriction, including
734
+ without limitation the rights to use, copy, modify, merge, publish,
735
+ distribute, sublicense, and/or sell copies of the Software, and to
736
+ permit persons to whom the Software is furnished to do so, subject to
737
+ the following conditions:
738
+
739
+ The above copyright notice and this permission notice shall be
740
+ included in all copies or substantial portions of the Software.
741
+
742
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
743
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
744
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
745
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
746
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
747
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
748
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.