Saving content of image box

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
BranFlayk
Posts: 10
Joined: Sun Dec 01, 2013 4:10 pm

Saving content of image box

Post by BranFlayk » Sun Nov 30, 2014 4:46 pm

Have been getting really frustrated with LiveCode this weekend :x
I'm writing a program to resize an image to 150 x 150. I've finally got the selected image to show up in an Image control (imgNewLogo) in the correct size.
Now trying to save that as a new image.
The code for my file save button is

Code: Select all

on mouseUp
   local pNewName,file_ext
   set the itemdelimiter to "."
   put the text of field "fldNewName" into pNewName

   #put toupper(item -1 of pNewName) into file_ext
   #if file_ext="PNG" then
      #export image "imgNewLogo" to file pNewName as PNG
   #else if (file_ext="JPG" or file_ext="JPEG") then
      #export image "imgNewLogo" to file pNewName as JPEG
   #end if   

   put image "imgNewLogo" into url ("binfile:" & pNewName)
end mouseUp
Using the "put image" line just makes an empty file, and the "export image" lines cause Livecode to crash with no explanation.
The value in field "fldNewName" is "/home/brian/Pictures/new_mario.png" (as an example), could someone tell me where I'm going wrong?

Thanks in advance

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Saving content of image box

Post by Klaus » Sun Nov 30, 2014 9:55 pm

Hi Bran,

hm, not sure, but sounds like the path is not valid!?
Is that a relative or absolute pathname?
Who entered that path into that field?
Did you via script?
Is this on Linux, Mac or Win? Looks like linux.
Can't you work with -> specialfolderpath("...")?

Questions, questions, questions... :D


Best

Klaus

BranFlayk
Posts: 10
Joined: Sun Dec 01, 2013 4:10 pm

Re: Saving content of image box

Post by BranFlayk » Sun Nov 30, 2014 10:41 pm

Hi Klaus, thanks for your reply.

The filename is created from an "ask file" command. I thought it was absolute, but now I'm not so sure.
I'm creating the program on my Linux PC at home, but I'm writing it for one of my tasks at work so it will be running on a Windows box there.
The aim of the code is to load an image (any size), resize it to 150x150 pixels and then save it at that size with a new file name.
I take the filename provided by "ask file", then before saving I add "new_" to the original filename.
Have attached the whole stack, hopefully that will explain it :-)
Attachments
resizer.zip
(1.81 KiB) Downloaded 217 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Saving content of image box

Post by jacque » Tue Dec 02, 2014 8:23 pm

I don't see any "ask file" command in the handler you posted. Since many of us usually don't have time to download and examine stacks, posting your scripts here is better if you want more and faster answers.

In general, you want the "ask file" command to be in the same handler where you save the file. You are correct that the file path returned is absolute. All you need to do is something like this:

Code: Select all

on doSave
  ask file "Save image as:" with fld "fldNewName"
  if it is empty then exit doSave
  put it into tFilename
  put img "imgNewLogo" into url ("binfile:" & tFilename)
end doSave
Edit: I just realized you've placed the file path into the field via "ask file" so my comment isn't correct. You might try the above anyway to see if it works though. Replace the file path (fld "fldNewName") with a suggested name instead, for example:

ask file "Save image as:" with "logoNEW.png"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply