0
$\begingroup$

As simple as it sounds, I do some writing to a file and then close it. Afterwards I run FilePrint[foo] but nothing shows up when running on the cloud, whereas when running on desktop, it does.

Ideas?

EDIT

Here's the code. It's silly though.


CloudDeploy[FormFunction[ {"Image" -> "Image", "Scale"->"Number" },
  Module[{},
    x=#Image;
    r = #Scale;
    ig = ColorConvert[x, "Grayscale"];
    str = OpenWrite["imgg.txt"];
    CloudExport[x, "JPG", "file"];
    x = Part[ImageDimensions[ig], 2];
    y = Part[ImageDimensions[ig], 1];
    kx = 2 r;
    ky = r;
    sx = x/kx;
    sy = y/ky;
    chars = {" ", ".", ",", ":",";","-","=", "+", "*","x", "#","%","X", "@"};
    f[z_] := chars[[Length[chars] - Floor[(Length[chars] - 1) z/255]]];
    Do[
      Do[
        WriteString[
          str,
          f[
            N[
              Mean[
                Mean[
                  ImageData[
                    ImageTake[ig, {kx*j, kx (j + 1)}, {ky*i, ky (i + 1)}], 
                    "Byte"]]], 
               3]]], 
        {i, 0, sy}]
        WriteString[str, "\n"],
      {j, 0, sx}];
    Close[str];]&, AppearanceRules -> {"Title" -> "IMG-2-ASCII"}]]

The following is a sample input and a sample output (image and the content of the file respectively).

Input

Random Google Image

Output

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::::::::::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::::::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-=+**xxxxxxx+=-;;;;;;;:::::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;=*#%%%%%%%%%%%%%%%#x*+=-;;;:::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-*#%%%%%%%%%%%%%%%%%%%%%%%#=;;:::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*%%%%%%%%%%%%%%%%%%###%%%%%%#-;;::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-#%%%%%%%%%%%%%%%%%##%%%%%#%#%%*;;;:::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;=#%%%%%%%%%%%%%%%%%%%%%%%###%#%%%=;;;::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;-#%%%%%%%%%%%%%%#xx**++++**x###%%%x;;;::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;x%%%%%%%%%%%%x+-;;;;;;::;-+x##%%%%%x;;;:::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;x%%%%%%%%%%%#+;::::::::::::;-x##%%%%%=;;;::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;+%%%%%%%%%#%%x-;;;;;:::::::::;;-*%%%%%x-;;::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;=#%%%%%%%%%%%%x=;;;;;::::::::::;;=#%%%%%+;;;:::::::::
;;;;;;;;;;;;;;;;;;;;;;;;x%%%%%%%%%%%%%#+-;:::::::::::::;-=+%%%%%x-;;:::::::::
;;;;;;;;;;;;;;;;;;;;;;;=%%%%%%%%%%%%%%#+--;;::::::;-++**+==*%%%%+-;::::::::::
;;;;;;;;;;;;;;;;;;;;;;-*#%%%%%%%%%%%%#x##%%#x=;::;;+x#%xx+;-##%%=;;;:::::::::
;;;;;;;;;;;;;;;;;;;;;;-x#%%%%%%%%%%%#x#x*x*=*=-;::;----;:;;-*%%%=;;;:::::::::
;;;;;;;;;;;;;;;;;;;;;;+##%%%%%%%%%%%#+-;;;;;---;::;;::::::;-;x%#-;;::::::::::
;;;;;;;;;;;;;;;;;;;;;-*x%%%%%%%%%%%%x=;:::::;;;;::::::::::;-+#%x-;;::::::::::
;;;;;;;;;;;;;;;;;;;;;*x#%%%%%%%%%##%x=;;::;;;;;;:::::;;::::;x%x=-;;::::::::::
;;;;;;;;;;;;;;;;;;;-x##%%%%%%%%%%%%%*=-;;;--;;--;;::::;--;;;x%+-;;:::::::::::
;;;;;;;;;;;;;;;;;;;+#%%%%#%%%%%%%%%%*=--==--;;;;;;;;;==:;;:=%+=;;::::::::::::
;;;;;;;;;;;;;;;;;;;x%%%%%%%%%%#%%%%%#+----=x*---;;:::=;::;+x-;;;:::::::::::::
;;;;;;;;;;;;;;;;;;=%###%%%%%%%%%%%%%%%*=;-;-==-;:::;;:::;*x=;;;::::::::::::::
;;;;;;;;;;;;;;;;;;x#x##%%%%%%%%%%%%%%%%x+-;;;---;;;;::::=+*;;::::::::::::::::
;;;;;;;;;;;;;;;;;-x##%%%%%%%%%%%%%%%%%%x*+=;;;::::::::::-----;;::::::::::::::
;;;;;;;;;;;;;;;;;**#%%%%%%%%#%%%%%%%%%%#*++=-;;::::::::;-::;---;:::::::::::::
;;;;;;;;;;;;;;;;+xx#%%%%%%%%%%%%%%%%%###x+==--;;;;;;;:::;-;:;;;;:::::::::::::
;;;;;;;;;;;;;;;+###%%%%%%%%%%%#xxx**##x**+=-;;;:::::::::::=+;::::::::::::::::
;;;;;;;;;;;;;;+##%%%%%%%%%%%%#+=x#x*=+==-----;:::::::;:::::=#-:::::::::::::::
;;;;;;;;;;;;-*##%%%%%%%%%%%%#*+==---:---;;;;;::::::::;::;;::=%+;:::::::::::::
;;;;;;;;;;;=x#%%%%%%%%%%%%%x=--;;;;-;:;:::::::::::::::::;;;;:-#=;;:::::::::::
;;;;;;;;;-+%%%%%%%%%%%##%%*=;;;;;:;;-:::::::::::::::::::;;;;;;-#-::::::::::::
;;;;;;;;-x%#%#%%%%%%%%*#%*-;;;::::::;;:::::::;;;:::::::::;;;;;;-#+;::::::::::
;;;;;;;=x##%####%%%#x%*%#=-;;;:::::::;;;;::;::::::::::::::;;;;;;=%x;:::::::::
;;;;;;=**####**#%%x=-%%%x=-;;;::::::::-::::::::::::::::::::;:::;;+%*::;::::::
;;;;;=+=*x#x**x%%x=--#%%+-;;;;;;;;;;;-+;-;;;::::::::::::::::::::;;*%+::::::::
;;;;;==*xx+==*%%x=-;+%%#=--;;;;;--;-=xx=+;;-;::::::::::::::::::::;-#x;::::;;;
;;--+*x*==-=*%%x=--+###x=----------=*#*-**--=;-=*=;:::::::::::::::;*=;::;:;;;
:==*x#=--;=+x%%*-;-x#xx*-----------=*#*-*##%%xx+*%X;::::::::;::::::=-=;:::;;+
$\endgroup$
  • 1
    $\begingroup$ Please provide a more detailed, but simple, example of what you did. This might be an issue with file paths and directories that are treated differently in the cloud than on the desktop. $\endgroup$ – Sjoerd C. de Vries Mar 29 '15 at 9:17
  • $\begingroup$ I've made an (relevant?) edit. Is that good enough? $\endgroup$ – Cehhiro Mar 30 '15 at 4:19
  • $\begingroup$ Your code appears to have a missing semicolon (;) between the expression Do[ ... {i, 0, sy}] and the expression WriteString[str, "\n"]. That's bound to be causing trouble although I don't fixing it will solve your problem. $\endgroup$ – m_goldberg Mar 30 '15 at 5:39
0
$\begingroup$

Apparently Print[] doesn't print to the output screen of the user. A workaround I found was to Import[] and show the string with some formatting.

CloudDeploy[FormFunction[ {"Image" -> "Image", "Scale"->"Number" },
  Module[{},
    x=#Image;
    r = #Scale;
    ig = ColorConvert[x, "Grayscale"];
    str = OpenWrite["imgg.txt"];
    CloudExport[x, "JPG", "file"];
    x = Part[ImageDimensions[ig], 2];
    y = Part[ImageDimensions[ig], 1];
    kx = 2 r;
    ky = r;
    sx = x/kx;
    sy = y/ky;
    chars = {" ", ".", ",", ":",";","-","=", "+", "*","x", "#","%","X", "@"};
    f[z_] := chars[[Length[chars] - Floor[(Length[chars] - 1) z/255]]];
    Do[
      Do[
        WriteString[
          str,
          f[
            N[
              Mean[
                Mean[
                  ImageData[
                    ImageTake[ig, {kx*j, kx (j + 1)}, {ky*i, ky (i + 1)}], 
                    "Byte"]]], 
               3]]], 
        {i, 0, sy}];
        WriteString[str, "\n"],
      {j, 0, sx}];
   Close[str];
   s = Import["imgg.txt"];
   ExportForm[Style[
s, Black,
FontFamily -> "American Typewriter"], "String"]
   ]&, AppearanceRules -> {"Title" -> "Image 2 ASCII"}]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.