【问题标题】:Change height and width of image using url of the external website using jquery使用 jquery 使用外部网站的 url 更改图像的高度和宽度
【发布时间】:2013-12-24 15:45:21
【问题描述】:

我的图片源中有网址 像这样 我在数组中得到这个值,例如。 img[0].so 是否可以用 php 或 jquery 更改它

http://feedtest.tecontent.com/image.php/cover.jpg?image=/covers/cover.jpg&width=400&height=571&quality=90

我想在加载时使用 JQuery 更改其高度和宽度是否可以使用 jquery

【问题讨论】:

    标签: javascript jquery url resize width


    【解决方案1】:

    如果远程站点接受新的宽度并根据您的需要显示图像,您可以这样做

    img[0] = preg_replace( array('/width=[0-9][0-9][0-9]/i', '/height=[0-9][0-9][0-9]/i'), array('width=200','height=200'), $content);
    

    【讨论】:

      【解决方案2】:

      第一步:我们可以写一个简单的函数来经常使用:

      function replaceUrlParam(url, paramName, paramValue){
          if(paramValue == null)
              paramValue = '';
          var pattern = new RegExp('\\b('+paramName+'=).*?(&|$)')
          if(url.search(pattern)>=0){
              return url.replace(pattern,'$1' + paramValue + '$2');
          }
          return url + (url.indexOf('?')>0 ? '&' : '?') + paramName + '=' + paramValue
      }
      

      第 2 步: 然后在需要时调用该函数,如下所示:

      //considering the below URL:
      var myUrl = 'http://feedtest.tecontent.com/image.php/cover.jpg?image=/covers/cover.jpg&width=400&height=571&quality=90';
      
      replaceUrlParam(myUrl,'width',999999); //adjust width as per our need;
      replaceUrlParam(myUrl,'height',88888); //adjust height as per our need;
      

      【讨论】:

        猜你喜欢
        • 2013-02-01
        • 2017-02-02
        • 2012-04-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-25
        相关资源
        最近更新 更多