douyangquan2474 2016-01-18 04:44
浏览 59
已采纳

如何在固定尺寸的框内按高度调整图像,并在上传后保持图像尺寸

My objective is to limit image size to height:160px; width:270px; by resizing image by its height. If it's possible, I want to let user crop image and upload to server. here is the link of example.

example of my code->

<div class="col-sm-12">
  <div class="hotel-list">
    <div class="row image-box hotel listing-style1">
      <div class="col-sm-6 col-md-4">
        <article class="box">
          <figure>
            <a href="#" class="popup-gallery image-container">
              <img width="270" height="160" alt="" src="../Done/images/sideWhite.jpg">
            </a>
          </figure>
          <div class="details" style="background-color:white;">
            <span class="price">
                                                            <small style="padding-left:1%;">avg/night</small>
                                                            $620
                                                        </span>
            <h2 style="margin-bottom:1%; color:#C11B17;"><label>trav...</label></h2>
            <h4>with me in my Ferrari at Mazda Raceway Laguna Seca</h4>
            <div class="feedback">
              <div data-placement="bottom" data-toggle="tooltip" class="five-stars-container" title="" data-original-title="4 stars"><span style="width: 80%;" class="five-stars"></span>
              </div>
              <span class="review red-color">270 reviews</span>
            </div>
            <div class="feedback">
              COUNTRY
              <span class="review red-color">Korea</span>
            </div>
            <div class="feedback">
              GUEST(S)
              <span class="review red-color">1 - 4</span>
            </div>
            <div class="action">
              <a class="button btn-small white" style="color:#dcdc00; border:solid 1px;">Save</a>
              <!--alan this button-->
              <a class="button btn-small green popup-map" href="#" data-box="48.856614, 2.352222">Explore</a>
            </div>
          </div>
        </article>
      </div>
      <div class="col-sm-6 col-md-4">
        <article class="box">
          <figure>
            <a href="#" class="popup-gallery">
              <img width="270" height="160" alt="" src="../Done/images/white1028.jpg">
            </a>
          </figure>
          <div class="details" style="background-color:white;">
            <span class="price">
                                                            <small style="padding-left:1%;">avg/night</small>
                                                            $620
                                                        </span>
            <h2 style="margin-bottom:1%; color:#C11B17;"><label>trav...</label></h2>
            <h4>with me in my Ferrari at Mazda Raceway Laguna Seca</h4>
            <div class="feedback">
              <div data-placement="bottom" data-toggle="tooltip" class="five-stars-container" title="" data-original-title="4 stars"><span style="width: 80%;" class="five-stars"></span>
              </div>
              <span class="review red-color">270 reviews</span>
            </div>
            <div class="feedback">
              COUNTRY
              <span class="review red-color">Korea</span>
            </div>
            <div class="feedback">
              GUEST(S)
              <span class="review red-color">1 - 4</span>
            </div>
            <div class="action">
              <a class="button btn-small white" style="color:#dcdc00; border:solid 1px;" data-toggle="model" data-target="#WishlistPopup">Save</a>
              <!--alan this button-->
              <a class="button btn-small green popup-map" href="#" data-box="48.856614, 2.352222">Explore</a>
            </div>
          </div>
        </article>
      </div>
      <div class="col-sm-6 col-md-4">
        <article class="box">
          <figure>
            <a href="#" class="popup-gallery">
              <img width="270" height="160" alt="" src="../Done/images/white1028.jpg">
            </a>
          </figure>
          <div class="details" style="background-color:white;">
            <span class="price">
                                                            <small style="padding-left:1%;">avg/night</small>
                                                            $620
                                                        </span>
            <h2 style="margin-bottom:1%; color:#C11B17;"><label>trav...</label></h2>
            <h4>with me in my Ferrari at Mazda Raceway Laguna Seca</h4>
            <div class="feedback">
              <div data-placement="bottom" data-toggle="tooltip" class="five-stars-container" title="" data-original-title="4 stars"><span style="width: 80%;" class="five-stars"></span>
              </div>
              <span class="review red-color">270 reviews</span>
            </div>
            <div class="feedback">
              COUNTRY
              <span class="review red-color">Korea</span>
            </div>
            <div class="feedback">
              GUEST(S)
              <span class="review red-color">1 - 4</span>
            </div>
            <div class="action">
              <a class="button btn-small white" style="color:#dcdc00; border:solid 1px;" data-toggle="model" data-target="#WishlistPopup">Save</a>
              <!--alan this button-->
              <a class="button btn-small green popup-map" href="#" data-box="48.856614, 2.352222">Explore</a>
            </div>
          </div>
        </article>
      </div>
      <div class="col-sm-6 col-md-4">
        <article class="box">
          <figure>
            <a href="#" class="popup-gallery">
              <img width="270" height="160" alt="" src="../Done/images/backWhite.jpg">
            </a>
          </figure>
          <div class="details" style="background-color:white;">
            <span class="price">
                                                            <small style="padding-left:1%;">avg/night</small>
                                                            $620
                                                        </span>
            <h2 style="margin-bottom:1%; color:#C11B17;"><label>trav...</label></h2>
            <h4>with me in my Ferrari at Mazda Raceway Laguna Seca</h4>
            <div class="feedback">
              <div data-placement="bottom" data-toggle="tooltip" class="five-stars-container" title="" data-original-title="4 stars"><span style="width: 80%;" class="five-stars"></span>
              </div>
              <span class="review red-color">270 reviews</span>
            </div>
            <div class="feedback">
              COUNTRY
              <span class="review red-color">Korea</span>
            </div>
            <div class="feedback">
              GUEST(S)
              <span class="review red-color">1 - 4</span>
            </div>
            <div class="action">
              <a class="button btn-small white" style="color:#dcdc00; border:solid 1px;" data-toggle="model" data-target="#WishlistPopup">Save</a>
              <!--alan this button-->
              <a class="button btn-small green popup-map" href="#" data-box="48.856614, 2.352222">Explore</a>
            </div>
          </div>
        </article>
      </div>
      <div class="col-sm-6 col-md-4">
        <article class="box">
          <figure>
            <a href="#" class="popup-gallery">
              <img width="270" height="160" alt="" src="../Done/images/sideWhite.jpg">
            </a>
          </figure>
          <div class="details" style="background-color:white;">
            <span class="price">
                                                            <small style="padding-left:1%;">avg/night</small>
                                                            $620
                                                        </span>
            <h2 style="margin-bottom:1%; color:#C11B17;"><label>trav...</label></h2>
            <h4>with me in my Ferrari at Mazda Raceway Laguna Seca</h4>
            <div class="feedback">
              <div data-placement="bottom" data-toggle="tooltip" class="five-stars-container" title="" data-original-title="4 stars"><span style="width: 80%;" class="five-stars"></span>
              </div>
              <span class="review red-color">270 reviews</span>
            </div>
            <div class="feedback">
              COUNTRY
              <span class="review red-color">Korea</span>
            </div>
            <div class="feedback">
              GUEST(S)
              <span class="review red-color">1 - 4</span>
            </div>
            <div class="action">
              <a class="button btn-small white" style="color:#dcdc00; border:solid 1px;" data-toggle="model" data-target="#WishlistPopup">Save</a>
              <!--alan this button-->
              <a class="button btn-small green popup-map" href="#" data-box="48.856614, 2.352222">Explore</a>
            </div>
          </div>
        </article>
      </div>
      <div class="col-sm-6 col-md-4">
        <article class="box">
          <figure>
            <a href="#" class="popup-gallery">
              <img width="270" height="160" alt="" src="../Done/images/sideGray.jpg">
            </a>
          </figure>
          <div class="details" style="background-color:white;">
            <span class="price">
                                                            <small style="padding-left:1%;">avg/night</small>
                                                            $620
                                                        </span>
            <h2 style="margin-bottom:1%; color:#C11B17;"><label>trav...</label></h2>
            <h4>with me in my Ferrari at Mazda Raceway Laguna Seca</h4>
            <div class="feedback">
              <div data-placement="bottom" data-toggle="tooltip" class="five-stars-container" title="" data-original-title="4 stars"><span style="width: 80%;" class="five-stars"></span>
              </div>
              <span class="review red-color">270 reviews</span>
            </div>
            <div class="feedback">
              COUNTRY
              <span class="review red-color">Korea</span>
            </div>
            <div class="feedback">
              GUEST(S)
              <span class="review red-color">1 - 4</span>
            </div>
            <div class="action">
              <a class="button btn-small white" style="color:#dcdc00; border:solid 1px;" data-toggle="model" data-target="#WishlistPopup">Save</a>
              <!--alan this button-->
              <a class="button btn-small green popup-map" href="#" data-box="48.856614, 2.352222">Explore</a>
            </div>
          </div>
        </article>
      </div>
    </div>
  </div>
</div>

</div>
  • 写回答

1条回答 默认 最新

  • dongnanke4106 2016-01-18 05:40
    关注

    I have found a github resource by Fengyuan Chen. It is licensed as MIT. As you wanted, it provides all solution for cropping the image. It is well documented as well. If you want the changes to be permanent, you can get cropped image data by using getCroppedCanvas([options]) and send it to server side languages like php for saving as image. Here is a link you can check for uploading canvas data to php: Uploading 'canvas' image data to the server

    Without the help of server side languages like php, all the changes will be temporary.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么改成输入一个要删除的数后现实剩余的数再输入一个删除的数再现实剩余的数用yes表示继续no结束程序
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?