Exported images growing in size

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
KimD
Posts: 223
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Exported images growing in size

Post by KimD » Fri Jul 10, 2015 11:06 am

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Exported images growing in size

Post by jmburnod » Fri Jul 10, 2015 11:48 am

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
https://alternatic.ch

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Exported images growing in size

Post by Klaus » Fri Jul 10, 2015 12:38 pm

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

KimD
Posts: 223
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Re: Exported images growing in size

Post by KimD » Fri Jul 10, 2015 1:07 pm

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

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Exported images growing in size

Post by Klaus » Fri Jul 10, 2015 1:17 pm

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

KimD
Posts: 223
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Re: Exported images growing in size

Post by KimD » Fri Jul 10, 2015 1:39 pm

Thanks Klaus

I'll play around with that

Regards

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Exported images growing in size

Post by Klaus » Fri Jul 10, 2015 3:19 pm

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

KimD
Posts: 223
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Re: Exported images growing in size

Post by KimD » Sat Jul 11, 2015 8:16 am

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

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: Exported images growing in size

Post by SparkOut » Sat Jul 11, 2015 9:45 am

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 :)

KimD
Posts: 223
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Re: Exported images growing in size

Post by KimD » Sat Jul 11, 2015 11:55 am

Thanks. That has cleared up one of the things that was confusing me ;-)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”