Paperclip uses the imagemagick resize options like 100x50>
, 100x50<
, 100x50#
etc to resize images.
See the link what options are available.
When you need to bulk rename files you can not call "mv *.foo *.bar
" to change the extension of all .foo
files to bar
(because bash resolves wildcards and replaces them with the list of matched files).
This works on linuxes who use the Perl version of the rename
command (like Ubuntu):
rename 's/\.foo$/\.bar/' *
You can also use this to rename other parts of the file, e.g. from flag_en.png
, flag_de.png
etc. to just en.png
or de.png
:
rename 's/^flag_//' *
Note that we used $
and ^
to explicitly look at the ...
When you use the send_file
method to send a local file to the browser, you can save resources on the application server by setting the :x_sendfile
option to true
. This option is activated by default for Rails 3, so you need to understand this.
What this option does is not to send any data at all, but rather set the local file path as a new response header:
X-Sendfile: /opt/www/awesome-project/shared/downloads/image.png
When the response comes back from Rails to...
A good tool to generate strong passwords and secrets is "apg". You can get it with
sudo apt-get install apg
To create a strong secret for sessions, hashed Paperclip paths, etc. say
apg -m128 -a1 -E\'\"
Arguments explained:
-m
parameter defines the secret length-a1
makes apg choose from all 7-bit ASCII characters instead of just the alphabet-E\'\"
excludes quote characters so you can easily paste the secret into a Ru...You need to install the following packages before you can build the Paperclip gem:
sudo apt-get install imagemagick librmagick-ruby
When using virtual attributes, the attached trait can be useful to automatically copy errors from one attribute to another.
Here is a typical use case where Paperclip creates a virtual attribute :attachment
, but there are validations on both :attachment
and :attachment_file_name
. If the form has a file picker on :attachment
, you would like to highlight it with errors from any attribute:
class Note < ActiveRecord::Base
has_attached_file :attachment
validates_attachment_presence :a...
When Paperclip attachments should only be downloadable for selected users, there are three ways to go.
The same applies to files in Carrierwave.
The first way is to store Paperclip attachments not in the default public/system
, but in a private path like storage
inside the current release. You should prefer this method when dealing with sensitive data.
Make ...
In july Google announced a new version of their image serach tool Google Images. But you won't find it on the German google.de site. To reach the new - as I may say, very much better - tool from germany, you have to surf to images.google.com. Et voilà!
Captify is a plugin for jQuery written by Brian Reavis (@brianreavis) to display simple, pretty image captions that appear on rollover
The box shadows created rendered in IE by CSS3PIE look darker and are blurred differently than in browsers that render box-shadow
natively.
If possible, try to be OK with this. If not, make an IE-only stylesheet that uses a different color and blur radius:
// Real browsers:
+box_shadow("0 4px 10px #bbb")
// IE with PIE:
+box_shadow("0 5px 15px #888")
We should try to package this solution in a neat way so we don't need different stylesheets.
See also this [cross-browser box-shadow comparison]...
Sometimes files attain executable-flags that they do not need, e.g. when your Windows VM copies them over a Samba share onto your machine.
From inside your Rails project directory call regularly:
geordi remove-executable-flags
Runs chmod -x
on Ruby, HTML, CSS, image, Rake and similar files.
This script is part of our geordi gem on github.
With this plugin, you can create a scalable tooltip by just using a single background image for the tooltip body.
You can write regular expressions some different ways, e.g. /regex/
and %r{regex}
. For examples, look here.
Remember that it is always a good idea to match a regex visually first.
Literal Characters
[ ] \ ^ $ . | ? * + ( )
Character Classes
[ae] matches a and e, e.g. gr[ae]y => grey or gray => but NOT graay or graey
[0-9] ...
So you screwed up and copied Paperclip secrets from one project to another. Here is a semi-automatic, painful way to migrate your existing attachment files to new locations.
You need to follow this step by step, do not just copy the whole thing into the console!
# 1. Get old paths by doing something like this on the console:
old_paths = ModelWithAttachment.all.collect { |m| [m.id, File.dirname(m.image.path(:original)).gsub(/original$/, '') ] if m.image.file? }.compact.uniq
# 2. Now change the Paperclip secret on the co...
The following Sass will do it:
hr
color: #ddd
background-color: #ddd
border: none
height: 1px
PaintbrushJS is a lightweight, browser-based image processing library that can apply various visual filters to images within a web page.
validates_attachment_content_type :image, :content_type => /^image\/(jpg|jpeg|pjpeg|png|x-png|gif)$/, :message => 'file type is not allowed (only jpeg/png/gif images)'
Some browsers render PNG images with color profiles and other shenanigans, some don't.
The cleanest way to have consistent colors across browsers is to convert all your images to a standard color profile, strip the image's original profile and attach the standard profile.
If you can't be bothered to convert color profiles, a quicker (but less effective) method is to remove some PNG chunks from your files.
[Geordi](https://git...
When a paperclip attachment gains a new style and you have many attachments, reprocessing can take ages. This is because all styles are being recomputed.
To create only missing images, patch Paperclip like this in your script that does the reprocessing:
Paperclip <2.3.2
class Paperclip::Attachment
private
def post_process_styles_with_extreme_lazyness
@old_styles = @styles
@styles = @styles.reject do |name, _|
exists?(name)
end
post_process_styles_without_extreme_...
has_attached_file(
:avatar,
:styles => { :large => "300x300", :small => "100x100" },
:convert_options => { all => "-colorspace RGB" }
)
script/runner -e development 'Article.all.each { |a| a.image.reprocess! if a.image.exists? }; "done"'
.notice,
.error,
.information,
.warning {
font-weight: bold;
}
.notice {
color: #11bb00;
}
.error {
color: #F53A31;
}
.information {
color: #557;
}
.warning {
color: #d07d2d;
}
Please keep this config simple. It should be a starting point for new developers learning Git.
[user]
name = Your Name
email = your.name@domain.com
[branch]
sort = -committerdate
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
whitespace = white reverse
meta = blue reverse
frag = blue reverse
old = red
new = green
[color "status"]
added = green
changed = yellow
untracked = cyan
[interactive]
singlekey = true # Do not requir...