writeImage function bug?

Hi all! I’ve been having this issue where when I load an image from a web request and then save it using the FileManager’s writeImage function, the image that is written has a file size that is much larger than it should be, would someone mind taking a look at my code and seeing if I’m doing something incorrect or if they have similar issues? I noticed that this issue only occurs while using the FileManager’s writeImage function (as opposed to, for example, the Photos.save() function). Any help would be greatly appreciated, as the file sizes are a huge memory suck! I also attached a screenshot showing the size of the file in the directory (I’m using a file bookmark leading to a folder in my iCloud directory). Also, the link to the original file is https://commons.wikimedia.org/wiki/File:Helianthus_decapetalus_‘Plenus’.jpg Please let me know if any other info is needed!:slight_smile:

const imLink = 'https://upload.wikimedia.org/wikipedia/commons/c/c1/Helianthus_decapetalus_%27Plenus%27.jpg'
var req = new Request(imLink);
var exImage = await req.loadImage();
var fm = FileManager.iCloud();
var path = fm.bookmarkedPath('example');
var path = `${path}/sunflower.jpeg`;
console.log(`Save Directory = ${path}`);
fm.writeImage(path, exImage);

(Screenshot of file in iCloud Directory)

Same result for me. 2.5 MB image saved as 9.1 MB. Exif shows nothing unusual from what I could see.

I would change it to not redefine path though; not that it makes any difference to the result.

1 Like

Hmm that’s bizzare, well glad to know it’s not just me, thank you for testing it out! and noted on the redefining path! When you say not to redefine, do you mean to assign the second path as a separate variable or just to drop the var declaration the second time? Thanks for the input!:slight_smile:

Personally unless I’m making something a scratch variable specifically to store whatever, whenever I try and avoid multi-facet data storage. A good database design principle I feel works well for coding too.

You define a variable with var twice and put two different paths in.

I would maybe define two different variables if I need both, but I’d only use var once for defining a variable called path.