Is there any codea trick / hack to export an image to photos or email it?
maybe with os.getenv() or http.request mailto:// and sending the image or something?
you mean ‘from a program by itself’?
yes
se24vad here’s a command to open the mail app and from the code you can attach the image
mailto://
I don’t think there is a way. Codea doesn’t seem to support any of the relevant APIs and the mailto: scheme doesn’t support attachments or basically anything other than plain text.
I think the closest you can get is assign an image to pasteboard.image and then open Mail via a mailto: link, then the user only has to paste the image.
If this is mainly for your own use, you can also save images to dropbox with saveImage(“Dropbox:…”,…) like you save to other sprite packs. You may have to hit the sync button in the sprite picker after that though…
thank you guys.
@se24vad - This may do the trick for email, insert the image as an HTML tag to the email body. Also you have to base64 image data.
-- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de>
-- licensed under the terms of the LGPL2
-- character table string
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-- encoding
function enc(data)
return ((data:gsub('.', function(x)
local r,b='',x:byte()
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
return r;
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if (#x < 6) then return '' end
local c=0
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
return b:sub(c+1,c+1)
end)..({ '', '==', '=' })[#data%3+1])
end
--
-- Read the image and base64 encode it
local filepath = "Documents/Chest Closed.png"
local file = io.open(os.getenv("HOME").."/"..filepath,"rb")
local data = enc(file:read("*all"))
file:close()
-- wrap it into urlencoded HTML imgage tag: <img src="data:image/png;base64,[data]" />
local imgtag = "%3Cimg%20src%3D%22data:image/png;base64,"..data.."%22%2F%3E"
openURL("mailto://foo@example.com?subject=Email%20image%20from%20Codea&body="..imgtag)
If your using the runtime, I have an Objective C library from it, but I assume your talking about from Codea. I think it’d also be possible to open a PHP script with the image data passed into it and have the script display it. Anther option would be to use the data:
URL prefix.
Thank’s - Yep it is really slow for big image, due o base64 encoding. And I’m unsure of a way to make a ‘fast’ lua based base64 encoder. Also there is probably a better solution to handle this, that’s the first idea that come into my mind apart from a server side solution. Maybe there is some gem to find from the url scheme docs… And sure, a server side solution would be fastest and avoid the need to switch to mail app.
@Jmv38 - I don’t know for IOS 7, but if I remember well, until IOS 6 there is an Apple restriction to prevent javascript execution from safari’s url scheme. One solution could be to ping back the javascript code from a server: send a request with your js to the server > server return an url > openUrl.