10 examples of 'get image width and height in jquery' in JavaScript

Every line of 'get image width and height in jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
3function calculateWidthHeightImg(width, height, image){
4 that = image;
5 var img = document.getElementById(image.attr('id'));
6 that = img;
7 var imgWidth = img.naturalWidth;
8 var imgHeight = img.naturalHeight;
9 var rel = width/height;
10 var imgRel = imgWidth/imgHeight;
11 if(imgRel > rel){
12 // set to max width.
13 if(imgWidth > width){
14 image.attr('width', width);
15 image.attr('height', width / imgWidth * imgHeight);
16 }
17 else
18 {
19 // do nothing our image should already fit.
20 }
21 }
22 else{
23 // set to max height.
24 if(imgHeight > height){
25 image.attr('height', height);
26 image.attr('width', height / imgHeight * imgWidth);
27 }else
28 {
29 // do nothing our image should already fit.
30 }
31 }
32}
17function get_size(img) {
18 return {
19 'width': img.get(0).naturalWidth,
20 'height': img.get(0).naturalHeight
21 };
22}
80function setImageSize(obj){
81 var imgWidth = $(obj).width();
82 var src = $(obj).attr("src");
83 var filter = ["ExpandedBlockStart.gif","ContractedBlock.gif"];
84
85 for(var i in filter){
86 var item = filter[i];
87 if(src.indexOf(item)>=0){
88 return;
89 }
90 }
91
92 if(imgWidth>=width)
93 {
94 $(obj).css("width","100%");
95 }
96}
160function imageWidth(img) {
161 const style = getComputedStyle(img);
162 return img.clientWidth
163 - parseFloat(style.paddingLeft)
164 - parseFloat(style.paddingRight);
165}
115export function getImageDimensions(src, callback) {
116 const img = new Image();
117
118 img.onload = () => {
119 const width = img.naturalWidth,
120 height = img.naturalHeight;
121
122 callback(width, height);
123 };
124
125 img.src = src;
126}
22getWidth() {
23 return this.width;
24}
1function iFrameHeight(iframe)
2{
3 var doc = 'contentDocument' in iframe ? iframe.contentDocument : iframe.contentWindow.document;
4 var height = parseInt(doc.body.scrollHeight);
5
6 if (!document.all)
7 {
8 iframe.style.height = parseInt(height) + 60 + 'px';
9 }
10 else if (document.all && iframe.id)
11 {
12 document.all[iframe.id].style.height = parseInt(height) + 20 + 'px';
13 }
14}
232function convertImageSize(image) {
233 //var texture = gl.createTexture();
234 //gl.bindTexture(gl.TEXTURE_2D, texture);
235 if (!isPowerOfTwo(image.width) || !isPowerOfTwo(image.height)) {
236 // Scale up the texture to the next highest power of two dimensions.
237 var canvas = document.createElement("canvas");
238 canvas.width = nextHighestPowerOfTwo(image.width);
239 canvas.height = nextHighestPowerOfTwo(image.height);
240 var ctx = canvas.getContext("2d");
241 ctx.drawImage(image, 0, 0, image.width, image.height);
242 image = canvas;
243 }
244 //gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
245 //gl.generateMipmap(gl.TEXTURE_2D);
246 //gl.bindTexture(gl.TEXTURE_2D, null);
247 //return texture;
248 return image;
249}
129function get_width(obj) {
130 return typeof obj == 'object' && obj && obj.width != undefined
131 ? obj.width
132 : ((typeof obj == 'object' && obj !== null ? utils.strlen(obj.text) : utils.strlen(obj)) + (style['padding-left'] || 0) + (style['padding-right'] || 0))
133}
69function getNaturalImageSize(img) {
70 return {
71 w: img.naturalWidth,
72 h: img.naturalHeight
73 };
74}

Related snippets