0

I need to control the weight and size in pixels of an image, this is my code:

<div class="control-group row">
            <%= f.fields_for :activity_documents, @activity.activity_documents do |builder| %>

            <div class="span6">
                <%= builder.label "Nombre de la imagen"  %>
                <%= builder.text_field :name, class:'imagen_file',:required => true, data:{required:true}, :placeholder=>'Nombre de la imagen' %>
            </div>

            <div class="span5">
                <%= builder.label "Imagen"  %>
                <% if builder.object.document_file_name? %>

                <%= image_tag builder.object.document.url, :id=>"file" %>&nbsp;&nbsp;&nbsp;


            <% else %>
                <%= builder.file_field :document, class:'form-control',data:{required:true}, style:'background-color:#e9e9e9; width:200px;', :id => 'file' %>


                <% end %>
                <%= builder.link_to_remove class:'btn btn-danger' do %>
                <i class="fa fa-minus"></i>
                <% end %>
            </div>
            <% end %>
        </div>

I need when I select an image check the resolution and weigh

Mike
  • 39
  • 9
  • Please take reference from this links for image validation (front side validation). 1. https://jsfiddle.net/RokoCB/7jc9v2gL/ 2. https://stackoverflow.com/questions/1310378/determining-image-file-size-dimensions-via-javascript – Ajay Barot Jul 04 '17 at 17:07
  • Please go through https://stackoverflow.com/a/44276469/5830036 – Mayur Shah Jul 05 '17 at 04:21

1 Answers1

0
$(document).ready(function(){
 var width = $('#file').width();
 var height = $('#file').height();
 if(width > 400 || height > 200){
 alert('please try a small image');
}
});
kajal ojha
  • 1,248
  • 8
  • 20