How do i get exact image size?

Hi Team,

I need to compress image if image size is > 1mb… I am able to compress it using code but can one tell me how to get exact size of image first ?

Thanks in Advance.

Regards,
Deepak

Hi @deepakchawla

  1. Assign Activity: Create a FileInfo object for the image file.
  2. If Activity: Check if the Length property is greater than 1,048,576.bytes (since 1MB is 1024 x 1024 bytes)

Here’s an example of the process:

  1. Assign:
  • To: imageFileInfo (Type: FileInfo)
  • Value: New FileInfo("path\to\your\image.jpg")
  1. If:
  • Condition: imageFileInfo.Length > 1048576
  • Then: Use your compression code here.

What would be the length if image size is 800 kb ?

My image size is 7435 kb and i am getting length 7613242.

Could you please explain ?

Hi @deepakchawla

You can achieve this using Get File Info Activity and check the Size

(ImageInfo.SizeInKB/1024) > 1

Cheers

Hi

Drag and drop the Get File info activity
In the File Path property of the activity, enter the path to the image file.
Create a variable to store the image size.

var imageSize = GetFileSize(“path/to/your/image.jpg”).Size;

→ Convert the size from bytes to megabytes (MB)
var imageSizeInMB = imageSize / (1024 * 1024);

→ Check if the image size is greater than 1MB
if (imageSizeInMB > 1) {

}

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.