Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何围绕x-y坐标动态裁剪图像?_Jquery_Ruby On Rails_Image_Crop - Fatal编程技术网

Jquery 如何围绕x-y坐标动态裁剪图像?

Jquery 如何围绕x-y坐标动态裁剪图像?,jquery,ruby-on-rails,image,crop,Jquery,Ruby On Rails,Image,Crop,所以我有一些erb,它根据用户的输入动态地生成一步一步的指令。在每个步骤中都有文本,然后至少有一个图像,图像标签覆盖在顶部(突出显示步骤说明文本所指的内容)。现在的问题是图像尺寸太大,不利于在手机上显示。(最大宽度为640像素)。我有每个标记的X-Y位置,所以我想在指令加载时动态地裁剪每个标记,以减小它们的宽度(我认为300px就可以了)。我想知道最好的办法是什么?提前谢谢 jQuery(标记的显示方式) $('span.i_contact')。每个(函数(){ var pos_width=$(

所以我有一些erb,它根据用户的输入动态地生成一步一步的指令。在每个步骤中都有文本,然后至少有一个图像,图像标签覆盖在顶部(突出显示步骤说明文本所指的内容)。现在的问题是图像尺寸太大,不利于在手机上显示。(最大宽度为640像素)。我有每个标记的X-Y位置,所以我想在指令加载时动态地裁剪每个标记,以减小它们的宽度(我认为300px就可以了)。我想知道最好的办法是什么?提前谢谢

jQuery(标记的显示方式)

$('span.i_contact')。每个(函数(){
var pos_width=$(此).data('pos-width');
var pos_height=$(此).data('pos-height');
var xpos=$(this).data('pos-x');
var ypos=$(this).data('pos-y');
var taggedNode=$('')
taggedNode.css({
“边框”:“5px实心橙色”,
“宽度”:位置宽度,
“高度”:位置高度,
“左”:XPO,
“顶级”:YPO
});
var n=$(this.data('index'))
$('.i_tagmap'+n).append(taggedNode)
console.log(taggedNode.position())
});
$(“span.o_触点”)。每个(函数(){
var pos_width=$(此).data('pos-width');
var pos_height=$(此).data('pos-height');
var xpos=$(this).data('pos-x');
var ypos=$(this).data('pos-y');
var taggedNode=$('')
taggedNode.css({
“边框”:“5px纯绿”,
“宽度”:位置宽度,
“高度”:位置高度,
“左”:XPO,
“顶级”:YPO
});
var n=$(this.data('index'))
$('.o_tagmap'+n).append(taggedNode)
});
雇员再培训局:


步
“橙色”)%%>
“绿色”)%%>


您可以在客户端试验Jcrop:

或服务器端的RMagick:

非常酷,如果您正在寻找端到端解决方案,它可以提供图像后处理功能。查看主页上的最后一个示例

$('span.i_contact').each(function() {                
    var pos_width = $(this).data('pos-width');
    var pos_height = $(this).data('pos-height');
    var xpos = $(this).data('pos-x');
    var ypos = $(this).data('pos-y');
    var taggedNode = $('<div class="tagged" />')
    taggedNode.css({
        "border":"5px solid orange",
        "width":pos_width,
        "height":pos_height,
        "left":xpos,
        "top":ypos
    });

    var n = $(this).data('index')
    $('.i_tagmap' + n).append(taggedNode)  
    console.log(taggedNode.position())    
});

$("span.o_contact").each(function() {            
    var pos_width = $(this).data('pos-width');
    var pos_height = $(this).data('pos-height');
    var xpos = $(this).data('pos-x');
    var ypos = $(this).data('pos-y');

    var taggedNode = $('<div class="tagged" />')
    taggedNode.css({
        "border":"5px solid green",
        "width":pos_width,
        "height":pos_height,
        "left":xpos,
        "top":ypos  
    });
    var n = $(this).data('index')
    $('.o_tagmap' + n).append(taggedNode)        
});
<% n = steps.index(step) %>
<h2 style="margin-left:20px;"> Step <%= n + 1%></h2>
<div class="stepcontainer">
<div class="steptext">
    <% if step.priority == 1 %>
        <%= "Plug the #{step.i_connection.cord_type.name} end of the cable into the #{step.i_product.full_name}.  Then plug the #{step.o_connection.cord_type.name} end into the #{step.o_product.full_name}." %>
    <% elsif step.priority == 2 %>
        <%= "Plug the #{step.i_connection.cord_type.name} end of the cable into the #{step.i_product.full_name}.  Then plug the #{step.o_connection.cord_type.name} end into the #{step.o_product.full_name}." %>
    <% elsif step.priority == 3 %>
        <%= "Plug the #{step.o_connection.product.full_name } #{step.o_connection.cord_type.name} Cable into the wall." %>
    <% elsif step.priority == 4 %>
        <%= "Plug the #{step.i_connection.cord_type.name} end of the cable into the #{step.i_connection.product.full_name}.  Then plug the #{step.o_connection.cord_type.name} end into the #{step.o_connection.product.full_name}." %>
    <% elsif step.priority == 5 %>
        <%= "Plug #{step.o_connection.product.full_name}" %>
    <% elsif step.priority == 6 %>
        <%= "Touch the #{step.o_connection.button.name} Button on the #{step.o_connection.product.full_name}" %>
    <% end %>
</div>
<div class="modalbutton">
<%= render(step.flags.new) %>   
</div>

<div class="productimg">    
    <span class="o_contact o_contact<%= n %>" data-pos-x="<%= step.o_connection.pos_x %>" data-pos-y="<%= step.o_connection.pos_y %>"  data-pos-width="<%= step.o_connection.pos_width %>" data-pos-height="<%= step.o_connection.pos_height %>" id="spanid<%= n %>" data-index="<%= n %>"> </span>

<% if step.input_contact.present? %>
    <span class="i_contact i_contact<%= n %>" data-pos-x="<%= step.i_connection.pos_x %>" data-pos-y="<%= step.i_connection.pos_y %>"  data-pos-width="<%= step.i_connection.pos_width %>" data-pos-height="<%= step.i_connection.pos_height %>" ="spanid<%= n %>" data-index="<%= n %>"></span>    

    <div id="image_panel<%= n %>" style="float:left; width:300px; position:relative;">
        <%= link_to image_tag(step.i_connection.image.image.url(:medium)), "#{step.i_connection.image.image.url(:large)}", class: "fancybox" %>
        <div class="i_tagmap<%= n %>"></div>
    </div>      
</div>

<div class="cableimg">
    <% if step.i_connection.cord_type.present? %>

            <%= image_tag(step.i_connection.cord_type.image.url(:thumb), :class => "orange")  %>
    <% end %>           
    <% end %>   

    <% if step.o_connection.cord_type.present? %>
            <%= image_tag(step.o_connection.cord_type.image.url(:thumb), :class => "green") %>      
    <% end %>
</div>

<% if step.o_connection.button.present? %>
    <div class="productimg">
        <div id="image_panel<%= n %>" style="float:left; width:300px; position:relative;">
            <%= link_to image_tag(step.o_connection.image.image.url(:medium)), "#{step.o_connection.image.image.url(:large)}", class: "fancybox" %>
            <div class="o_tagmap<%= n %>"></div>
        </div>  
    </div>

<% else %>
    <div class="productimg">
        <div id="image_panel<%= n %>" style="float:left; width:300px; position:relative;">
            <%= link_to image_tag(step.o_connection.image.image.url(:medium)), "#{step.o_connection.image.image.url(:large)}", class: "fancybox" %>
            <div class="o_tagmap<%= n %>"></div>
        </div>  
    </div>              
<% end %>
</div>
<br>