Page 1 of 1

Saving content of image box

Posted: Sun Nov 30, 2014 4:46 pm
by BranFlayk
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

Re: Saving content of image box

Posted: Sun Nov 30, 2014 9:55 pm
by Klaus
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

Re: Saving content of image box

Posted: Sun Nov 30, 2014 10:41 pm
by BranFlayk
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 :-)

Re: Saving content of image box

Posted: Tue Dec 02, 2014 8:23 pm
by jacque
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"