At the beginning it seemed to me a like a mistype but now as I see more examples I realize its not..
I see :thumb => "300x300>"
or :thumb => "100x100#"
and even :thumb => "180"
what do these mean? Where can I find explanation for that notation?
On the git repository where it is developed. Explanation copied from there:
Resizing options
Default behavior is to resize the image and maintain aspect ratio (i.e. the :medium version of a 300×150 image will be 200×100). Some commonly used options are:
trailing #, thumbnail will be centrally cropped, ensuring the requested dimensions.
trailing >, thumbnail will only be modified if it is currently larger requested dimensions. (i.e. the :small thumb for a 120×80 original image will be unchanged)
Related
Like the first image, the meta tag is displayed correctly in inspect elements mode but incorrectly displayed in view page source mode as in the second image. Thank you for suggesting a solution to this problem.
I understood the answer:
Because, by default, the HTML encoding engine will only safelist the basic latin alphabet (because browsers have bugs. So we're trying to protect against unknown problems). The &XXX values you see still render as correctly as you can see in your screen shots, so there's no real harm, aside from the increased page size.
If the increased page size bothers you then you can customise the encoder to safe list your own character pages (not language, Unicode doesn't think in terms on language)
To widen the characters treated as safe by the encoder you would insert the following line into the ConfigureServices() method in startup.cs;
services.AddSingleton<HtmlEncoder>(
HtmlEncoder.Create(allowedRanges: new[] { UnicodeRanges.BasicLatin,
UnicodeRanges.Arabic }));
Arabic has quite a few blocks in Unicode, so you may need to add more blocks to get the full range you need.
i have a problem i am deveoping a application using rails 2.3.8 . my problem is with the pdf. when a generated the pdf it shows all images in Linux.(ubuntu)
but the same code when i tried in windows7 the pdf is not showing the images in the body.the header and footer images are loading. the header and footer in the layout. i am using wickedpdf for pdf generation.
my code is
<%= wicked_pdf_image_tag "#{Rails.root}/public/images/master_student/profile/default_student.png" ,:width=>85,:height=>100 %>
the code working fine in the ubuntu but not working in the windows7..
please help
I just overcame a similar issue on Windows with images uploaded through Paperclip, because WickedPDF's wicked_pdf_image_tag helper requires the images to be in public/images.
I used the solution given here for that problem, but I still couldn't get the images to render in the PDF. Then I discovered that if I put the image into the public/images folder and referenced it that way, the wicked_pdf_image_tag helper rendered the image tag with forward slashes instead of backslashes after the 'file://'.
This is the helper method I ended up with, which replaces wicked_pdf_image_tag:
module ApplicationHelper
def wicked_pdf_image_tag_for_public(img, options={})
if img[0] == "/"
# Remove the leading slash
new_image = img.slice(1..-1)
image_tag "file:///#{Rails.root.join('public', new_image).to_s.gsub("/", "\\")}"
else
image_tag "file://#{Rails.root.join('public', 'images', img).to_s.gsub("/", "\\")}}", options
end
end
end
Is it possible to retrieve the dimensions of an image stored on Amazon S3?
If the answer is no, are there any other ways around it other than downloading the image to my server to which sounds inefficient?
I'm using version 2 of the AWS SDK for PHP.
I've been looking through what is returned from the following code but doesn't seem to give dimensions.
$result = $s3->getObject(array(
'Bucket' => 'BUCKET_NAME',
'Key' => 'KEY_NAME'
));
var_dump($result);
I'm not 100% familiar with SDK2. With 1.5 you could do this
getimagesize($s3->get_object_url($bucket,$filename));
I think this is still possible as long as you can access publicly the image (or you have to find your way around authorized urls)
Obviously, your php must be enabled to open remote files.
I agree with the db cache. I run every image filename through a class that checks mysql for a match. If it finds one, it returns width, height and a preformatted sizetag ready to go. If the image and size are not found, it uses getimagesize() to return the same info, which it stores for next time. I also built in a resize method should I want to cheat a bit and resize the sizetag (but not the file) proportionally on the fly.
I don't know if storing the info is faster than getimagesize() as it downloads. S3 is pretty fast.
Due to lack of response I'll presume it's not possible... Didn't r3ally want to do it with JavaScript but this is how I did it.
<img src="image.jpg" id="image" />
<script>
// This runs after the image has loaded
$('#image').load(function() {
// Use the below code to get the height and width
// document.getElementById('image').width
// document.getElementById('image').height
});
</script>
Does anybody know how to upload a document to later show in a Rails application (as text)? Is Paperclip the right gem to do this? If it is how? (I have uploaded images before with Paperclip).
I like Paperclip. It seems well documented, and has worked well for everything I have needed. (I don't personally know any of them, but the clever folks at Thoughbot have created some pretty useful stuff, for which I feel indebted to them).
Obviously, you need to add Paperclip to your Gemfile, and (if you are using bundler) do your bundle install
Add to your model
has_attached_file :aFile
Add to you controller something to catch whatever you name it in your view (probably in your create and update methods)
#profile.aFile = params[:profile][:aFile]
Probably should check for its existence, if it is a required param
if params[:profile][:aFile].blank?
redirect_to #profile
else
render :action => 'do_something_interesting_with_file'
end
And that's about it. Don't forget your config entries. For example, if you are using some kind of post-processing on the file
Paperclip.options[:command_path] = "/opt/local/bin/"
I found this to be extraordinarily helpful
RailsCast by Ryan Bates
I have a validation in my Rails (3.1.4) model to make sure no one tries to upload anything malicious in leiu of their profile image, but when I try to upload a jpeg, the validation is triggering. I'm using the Paperclip gem and I'm unsure if that is having an impact.
validation in user.rb model
validates_attachment_content_type :profile_image, :content_type => ['image/jpeg', 'image/png', 'image/gif'], :message => "Only jpeg, gif and png files are allowed for profile pictures"
When I look at the properties of the jpeg locally (Windows O/S):
Item type = JPEG image
Type of file: JPEG image (.jpg)
Am I doing something wrong in my validation?
Also, when it triggers, it puts the model and field name before the message. Is there a way to avoid that? ie 'Profile image profile image content type Only jpeg, gif and png files are allowed for profile pictures'
Thank you!
You should add 'image/jpg' to the content type array, I think that's what you're missing.