Page 1 of 1

Exported images growing in size

Posted: Fri Jul 10, 2015 11:06 am
by KimD
Windows 7 & Livecode 7.0.6

I have a stack with a single card on it, and a single button on the card. The script of the button is -

on mouseUp
Import paint from file "Map.jpg"
Export last image to file "MapAfterImport.jpg" as JPEG
end mouseUp

There is no other script in the stack. The original Map.jpg file is 8Mb. When I press the button, Livecode writes a MapAfterImport.jpg file onto my desktop - which is 22Mb.

I'd appreciate any info on why importing and exporting a file would treble its size, and what I can do to avoid this happening.

Thanks in advance

Re: Exported images growing in size

Posted: Fri Jul 10, 2015 11:48 am
by jmburnod
Hi Kim,
This is the same with OSX.
You can get the text of image and export it like this :

Code: Select all

   put the text of last img into tDataImg
   put tDataImg into url("binfile:" & "MapAfterImport.jpg")
Best regards
Jean-Marc

Re: Exported images growing in size

Posted: Fri Jul 10, 2015 12:38 pm
by Klaus
Hi Kim,

1. welcome to the forum! :D
2. you could "play around" with the JPEGQualtity (0 - 100) before exporting.
...
set the JPEGQuality to 50
export last image to file "MapAfterImport.jpg" as JPEG
...

Best

Klaus

Re: Exported images growing in size

Posted: Fri Jul 10, 2015 1:07 pm
by KimD
Thanks Jean-Marc & Klaus

I got Jean-Marc's suggestion to work immediately, so I didn't try Klaus's (although I'll store it away for future use).

While I have some people who know what they are doing listening, can I ask another question?

I'm trying to copy an image, to the same location (card or group), but assign the copy a new name. I need to do this because I want to edit the copy while retaining the original.

I have this working, but intuitively my solution seems too complicated
- copy the image into a temp location
- (re)name the version of the image that is in the temp location
- copy the renamed image back into the original location
- delete the contents of the image in the temp location
It works, but I hate it.

I also played around with a solution using "last image" but couldn't get that to work.

What is the simplest way to create a copy of an image, where the copy has a new name, in the same card/group as the original image?

Regards

Re: Exported images growing in size

Posted: Fri Jul 10, 2015 1:17 pm
by Klaus
Hi Kim,

just made a quick test and this worked fine (copy image to same card)

Code: Select all

on mouseUp
   copy img "old image" to this cd
   set the name of last img to "new image"
end mouseUp
You may want to take a look at these great example/learning stacks:
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

Re: Exported images growing in size

Posted: Fri Jul 10, 2015 1:39 pm
by KimD
Thanks Klaus

I'll play around with that

Regards

Re: Exported images growing in size

Posted: Fri Jul 10, 2015 3:19 pm
by Klaus
Hi Kim,

another way is to directly copy the image on the disk!
No need to import and export again:
...
put url("binfile:Map.jpg") into url("binfile:MapWithoutImport.jpg")
...
Done :D

Make sure the image is in the current DEFAULTFOLDER.


Best

Klaus

Re: Exported images growing in size

Posted: Sat Jul 11, 2015 8:16 am
by KimD
Hi Klaus

Sorry if this is a dumb question, but when should I use Binfile and when should I use File? Aren't all files stored on computers "binary"? By way of a note - I trained & worked as a programmer a long time ago, then got out of it. I've missed everything that has happened in programming since Back to the Future part II ;-)

Regards

Re: Exported images growing in size

Posted: Sat Jul 11, 2015 9:45 am
by SparkOut
By default, LiveCode will represent file content as text, and helpfully interpret line endings according to the platform. So on Windows you will get crlf inserted/ converted when saving to a file. This helps readability and transportability cross-platform, but will obviously break a file with content that is not human-readable, such as a jpeg image or audio file. In those cases using "binfile" will preserve the file contents faithfully, without interpretation of any line ending bytes in the file, since they aren't typically line ending markers.
Not a dumb question at all :)

Re: Exported images growing in size

Posted: Sat Jul 11, 2015 11:55 am
by KimD
Thanks. That has cleared up one of the things that was confusing me ;-)