How to get Image File Size after Resizing image in Javascript?
up vote
2
down vote
favorite
Given the below script, I could be able to resize image to the maximum pre-define dimension of image, and it was displaying in the Canvas
:
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
this.src = canvas.toDataURL();
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
However, I would like to get the file size of resized image; it is not the width and the height.
How can I get the image file size after it was resized?
Thanks.
javascript
add a comment |
up vote
2
down vote
favorite
Given the below script, I could be able to resize image to the maximum pre-define dimension of image, and it was displaying in the Canvas
:
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
this.src = canvas.toDataURL();
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
However, I would like to get the file size of resized image; it is not the width and the height.
How can I get the image file size after it was resized?
Thanks.
javascript
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Given the below script, I could be able to resize image to the maximum pre-define dimension of image, and it was displaying in the Canvas
:
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
this.src = canvas.toDataURL();
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
However, I would like to get the file size of resized image; it is not the width and the height.
How can I get the image file size after it was resized?
Thanks.
javascript
Given the below script, I could be able to resize image to the maximum pre-define dimension of image, and it was displaying in the Canvas
:
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
this.src = canvas.toDataURL();
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
However, I would like to get the file size of resized image; it is not the width and the height.
How can I get the image file size after it was resized?
Thanks.
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
this.src = canvas.toDataURL();
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
this.src = canvas.toDataURL();
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
javascript
javascript
asked Nov 11 at 12:46
Houy Narun
244422
244422
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You can calculate a rough size in bytes by doing newImageData.length * 3 / 4
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
//Line added
var canvasData = canvas.toDataURL();
//Line edited
this.src = canvasData;
//Line added
console.log(canvasData.length * 3 / 4, ' bytes');
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
it does not work atnewImageData.length
Cannot read property 'length' of undefined. Thanks
– Houy Narun
Nov 11 at 12:55
I'm correcting it.
– Bhaskar Choudhary
Nov 11 at 12:55
Check if the size is computed correctly or not :). Side note - For some reason onload function is being executed multiple times on my browser.
– Bhaskar Choudhary
Nov 11 at 13:18
On my windows pc, I right clicked and saved the image file and checked its size it showed Size: 15.0 KB (15,408 bytes) while the computed size is 15,425 bytes. This is what I meant by rough size.
– Bhaskar Choudhary
Nov 11 at 13:20
1
I solved that by defining variablecanvas
outsideimg.onload=function()..
, it works for me. Thanks for your help me :)
– Houy Narun
Nov 11 at 15:55
|
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can calculate a rough size in bytes by doing newImageData.length * 3 / 4
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
//Line added
var canvasData = canvas.toDataURL();
//Line edited
this.src = canvasData;
//Line added
console.log(canvasData.length * 3 / 4, ' bytes');
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
it does not work atnewImageData.length
Cannot read property 'length' of undefined. Thanks
– Houy Narun
Nov 11 at 12:55
I'm correcting it.
– Bhaskar Choudhary
Nov 11 at 12:55
Check if the size is computed correctly or not :). Side note - For some reason onload function is being executed multiple times on my browser.
– Bhaskar Choudhary
Nov 11 at 13:18
On my windows pc, I right clicked and saved the image file and checked its size it showed Size: 15.0 KB (15,408 bytes) while the computed size is 15,425 bytes. This is what I meant by rough size.
– Bhaskar Choudhary
Nov 11 at 13:20
1
I solved that by defining variablecanvas
outsideimg.onload=function()..
, it works for me. Thanks for your help me :)
– Houy Narun
Nov 11 at 15:55
|
show 2 more comments
up vote
0
down vote
accepted
You can calculate a rough size in bytes by doing newImageData.length * 3 / 4
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
//Line added
var canvasData = canvas.toDataURL();
//Line edited
this.src = canvasData;
//Line added
console.log(canvasData.length * 3 / 4, ' bytes');
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
it does not work atnewImageData.length
Cannot read property 'length' of undefined. Thanks
– Houy Narun
Nov 11 at 12:55
I'm correcting it.
– Bhaskar Choudhary
Nov 11 at 12:55
Check if the size is computed correctly or not :). Side note - For some reason onload function is being executed multiple times on my browser.
– Bhaskar Choudhary
Nov 11 at 13:18
On my windows pc, I right clicked and saved the image file and checked its size it showed Size: 15.0 KB (15,408 bytes) while the computed size is 15,425 bytes. This is what I meant by rough size.
– Bhaskar Choudhary
Nov 11 at 13:20
1
I solved that by defining variablecanvas
outsideimg.onload=function()..
, it works for me. Thanks for your help me :)
– Houy Narun
Nov 11 at 15:55
|
show 2 more comments
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can calculate a rough size in bytes by doing newImageData.length * 3 / 4
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
//Line added
var canvasData = canvas.toDataURL();
//Line edited
this.src = canvasData;
//Line added
console.log(canvasData.length * 3 / 4, ' bytes');
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
You can calculate a rough size in bytes by doing newImageData.length * 3 / 4
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
//Line added
var canvasData = canvas.toDataURL();
//Line edited
this.src = canvasData;
//Line added
console.log(canvasData.length * 3 / 4, ' bytes');
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
//Line added
var canvasData = canvas.toDataURL();
//Line edited
this.src = canvasData;
//Line added
console.log(canvasData.length * 3 / 4, ' bytes');
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
$(function()
$("#file_select").change(function(e)
var fileReader = new FileReader();
fileReader.onload = function(e)
var img = new Image();
img.onload = function()
var MAX_WIDTH = 100;
var MAX_HEIGHT = 100;
var width = img.width;
var height = img.height;
if (width > height)
if (width > MAX_WIDTH)
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
else
if (height > MAX_HEIGHT)
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
var canvas = document.createElement("canvas");
canvas.setAttribute('id', 'canvas')
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(this, 0, 0, width, height);
//Line added
var canvasData = canvas.toDataURL();
//Line edited
this.src = canvasData;
//Line added
console.log(canvasData.length * 3 / 4, ' bytes');
document.body.appendChild(this); //remove this if you don't want to show it
img.src = e.target.result;
fileReader.readAsDataURL(e.target.files[0]);
// console.log('file size after resized is...');
);
);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<h1 class="logo">Upload Picture</h1>
<div id="upload_form_div">
<form id="upload_form" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file" capture="camera" id="file_select" />
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
edited Nov 11 at 13:11
answered Nov 11 at 12:49
Bhaskar Choudhary
1158
1158
it does not work atnewImageData.length
Cannot read property 'length' of undefined. Thanks
– Houy Narun
Nov 11 at 12:55
I'm correcting it.
– Bhaskar Choudhary
Nov 11 at 12:55
Check if the size is computed correctly or not :). Side note - For some reason onload function is being executed multiple times on my browser.
– Bhaskar Choudhary
Nov 11 at 13:18
On my windows pc, I right clicked and saved the image file and checked its size it showed Size: 15.0 KB (15,408 bytes) while the computed size is 15,425 bytes. This is what I meant by rough size.
– Bhaskar Choudhary
Nov 11 at 13:20
1
I solved that by defining variablecanvas
outsideimg.onload=function()..
, it works for me. Thanks for your help me :)
– Houy Narun
Nov 11 at 15:55
|
show 2 more comments
it does not work atnewImageData.length
Cannot read property 'length' of undefined. Thanks
– Houy Narun
Nov 11 at 12:55
I'm correcting it.
– Bhaskar Choudhary
Nov 11 at 12:55
Check if the size is computed correctly or not :). Side note - For some reason onload function is being executed multiple times on my browser.
– Bhaskar Choudhary
Nov 11 at 13:18
On my windows pc, I right clicked and saved the image file and checked its size it showed Size: 15.0 KB (15,408 bytes) while the computed size is 15,425 bytes. This is what I meant by rough size.
– Bhaskar Choudhary
Nov 11 at 13:20
1
I solved that by defining variablecanvas
outsideimg.onload=function()..
, it works for me. Thanks for your help me :)
– Houy Narun
Nov 11 at 15:55
it does not work at
newImageData.length
Cannot read property 'length' of undefined. Thanks– Houy Narun
Nov 11 at 12:55
it does not work at
newImageData.length
Cannot read property 'length' of undefined. Thanks– Houy Narun
Nov 11 at 12:55
I'm correcting it.
– Bhaskar Choudhary
Nov 11 at 12:55
I'm correcting it.
– Bhaskar Choudhary
Nov 11 at 12:55
Check if the size is computed correctly or not :). Side note - For some reason onload function is being executed multiple times on my browser.
– Bhaskar Choudhary
Nov 11 at 13:18
Check if the size is computed correctly or not :). Side note - For some reason onload function is being executed multiple times on my browser.
– Bhaskar Choudhary
Nov 11 at 13:18
On my windows pc, I right clicked and saved the image file and checked its size it showed Size: 15.0 KB (15,408 bytes) while the computed size is 15,425 bytes. This is what I meant by rough size.
– Bhaskar Choudhary
Nov 11 at 13:20
On my windows pc, I right clicked and saved the image file and checked its size it showed Size: 15.0 KB (15,408 bytes) while the computed size is 15,425 bytes. This is what I meant by rough size.
– Bhaskar Choudhary
Nov 11 at 13:20
1
1
I solved that by defining variable
canvas
outside img.onload=function()..
, it works for me. Thanks for your help me :)– Houy Narun
Nov 11 at 15:55
I solved that by defining variable
canvas
outside img.onload=function()..
, it works for me. Thanks for your help me :)– Houy Narun
Nov 11 at 15:55
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248880%2fhow-to-get-image-file-size-after-resizing-image-in-javascript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown