[英]Change height and width of image using url of the external website using jquery
i have url in my image source like this i get this value in array for eg. 我在这样的图像源中有网址,例如,我在数组中获取此值。 img[0].so is it possible to change it with php or jquery
img [0] .so是否可以用php或jquery进行更改
http://feedtest.tecontent.com/image.php/cover.jpg?image=/covers/cover.jpg&width=400&height=571&quality=90
i want change its height and width using JQuery when they load is it possible using jquery 我想在加载时使用JQuery更改其高度和宽度,是否可以使用jquery
如果远程站点接受新宽度并根据需要显示图像,则可以执行以下操作
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);
Step-1: We can write a simple function to be used freequently: 步骤1:我们可以编写一个可供自由使用的简单函数:
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
}
Step-2: then calling the function whenever we need like below: 步骤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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.