help with a script to auto-generate images

Discussion in 'macOS' started by sk3pt1c, Dec 17, 2010.

  1. sk3pt1c macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #1
    hi there, i've posted this again in the design forum cause i thought it could be done with photoshop

    http://forums.macrumors.com/showthread.php?p=11580980

    the idea is to open a text file that contains lines of filenames, like

    kfgdkfg-dfgdg-dfgd.jpeg

    and create blank dummy images using those filenames.

    some people suggested Automator, some PDFs...

    any ideas?

    thanks in advance!
     
  2. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #2
    This really isn't hard to do, but requires some programming to do it. My preferred solution involves a small Java application that reads in the supplied text file, parses it for image names, and creates dummy images out of those file names. I can also perform some simple transforms on the generated images with this setup - for example, changing the color of the dummy images from all black to something else. I could probably whip up a solution for this very problem in 30 minutes or so in Java ;)
     
  3. sk3pt1c thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #3
    wow, you *are* a demi-god! :)

    i've done some java in the past but there's no way i remember enough of it to do this right now... i get what you're implying though, you just go through the file line by line, pull the strings and create-save files with them as filenames, right?

    how would we run that on a mac? (no idea, have never programmed on a mac)
    :D
     
  4. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #4
    You've got three options here.

    I could make it a command-line application: The only argument it takes is the text file to parse.
    I could make it a GUI: The first thing the application does is prompts for the location of the input file, with a standard Open File dialog.
    I could make it BOTH - if no arguments are passed in, use GUI mode, otherwise use command-line mode.

    All of these options aren't terribly difficult to implement, given the nature of the problem.

    As for running the application once it is created:
    Command line version, at the Terminal prompt:
    Code:
    java -jar (drag the JAR file to the Terminal window) (drag the text file to the Terminal window)
    GUI version:
    Double-click the JAR file. That's it!
     
  5. sk3pt1c thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #5
    command line would be fine i guess, if it's only to pass it the text file as the argument and have it generate the pics in the same folder as the text file.
    but please only do this if you have enough spare time you're willing to devote to it and it will take a short amount of time to code.
    again, thank you so much!
     
  6. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #6
    All done!

    To use this command-line program:
    Code:
    cd (drag folder where JAR and input file are located to Terminal window)
    java -jar DummyImageGenerator.jar inputfile.txt
    I've included an example input file in the zip archive.

    The program generates 64x64 pixel images from the file names given.
     

    Attached Files:

    • DIG.zip
      File size:
      1.9 KB
      Views:
      19
  7. sk3pt1c thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #7
    first of all, thanks a million for this! :D

    but i got this output:

    Code:
    java.io.FileNotFoundException:  (No such file or directory)
    	at java.io.RandomAccessFile.open(Native Method)
    	at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
    	at javax.imageio.stream.FileImageOutputStream.<init>(FileImageOutputStream.java:53)
    	at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(FileImageOutputStreamSpi.java:37)
    	at javax.imageio.ImageIO.createImageOutputStream(ImageIO.java:393)
    	at javax.imageio.ImageIO.write(ImageIO.java:1520)
    	at dummyimagegenerator.Main.main(Main.java:41)
    An unknown error has occurred:
    java.lang.NullPointerException
    	at javax.imageio.ImageIO.write(ImageIO.java:1529)
    	at dummyimagegenerator.Main.main(Main.java:41)
    sk3pt1cs-MacBookPro:test ioannisaliazis$ java -jar DummyImageGenerator.jar test.txt
    java.io.FileNotFoundException:  (No such file or directory)
    	at java.io.RandomAccessFile.open(Native Method)
    	at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
    	at javax.imageio.stream.FileImageOutputStream.<init>(FileImageOutputStream.java:53)
    	at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(FileImageOutputStreamSpi.java:37)
    	at javax.imageio.ImageIO.createImageOutputStream(ImageIO.java:393)
    	at javax.imageio.ImageIO.write(ImageIO.java:1520)
    	at dummyimagegenerator.Main.main(Main.java:41)
    An unknown error has occurred:
    java.lang.NullPointerException
    	at javax.imageio.ImageIO.write(ImageIO.java:1529)
    	at dummyimagegenerator.Main.main(Main.java:41)
    i tried to open your .jar file in a text editor but got crazy characters (maybe an encoding issue?), i'm downloading xcode now to see if that can open it properly...

    i ran the command properly, there's no issue there, i am versed in both unix and java, just not to your level i suppose, which is why i needed the help :)
     
  8. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #8
    That'll happen if you forget to change directories with the cd command to the folder the text file lives in. Note that if you put the JAR file and the text file in different folders, you'll have to drag the JAR to the Terminal window to get the proper path to it after the java -jar part of the command.

    Also, you're not supposed to open the JAR file in a text editor. It contains binary data, not meant to be read by humans. If you're looking for the source code (to look at in a text editor), I can provide that too.
     
  9. sk3pt1c thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #9
    no, i was in the right folder mate :)

    oh, ok, could i have that then please?
     
  10. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #10
    Here it is, the DummyImageGenerator source code. This was built with NetBeans 6.9.1 on Snow Leopard, but should work on any Java IDE.
     

    Attached Files:

  11. sk3pt1c, Dec 21, 2010
    Last edited by a moderator: Dec 21, 2010

    sk3pt1c thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #11
    excuse the delay my friend, i forgot to mention that i get a file created with the filename ˇ˛0 and then the FileNotFoundException...

    both the jar file and the test.txt file are in the same folder

    i've tried doing it with full paths like this:

    java -jar /Users/ioannisaliazis/Desktop/mitsos/DummyImageGenerator.jar /Users/ioannisaliazis/Desktop/mitsos/test.txt

    as well as with just the filenames like this:

    java -jar DummyImageGenerator.jar test.txt

    and i still get errors...

    your files run properly so i'm guessing it's the underscore (eg. filename: 02006_7610583070135.JPG) in the filenames in my text file that's causing the whole thing to throw a fit?

    scratch that, i pasted all my text into your text file and it works fine, no idea why but it does, so i'll just leave the files as they are and paste into your text file when we have all the codes

    thanks a lot!

    (if you are as curious as i am though, give me an email via pm and i'll email you the files i've been trying with, i would like to figure out what's wrong with them)
     
  12. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #12
    I suspect the problem is an encoding issue. Java expects UTF-8 encoding with no byte order mark (BOM) for text files, which is the encoding I used. The free TextWrangler can convert files from one encoding to another easily. I also used Unix-style line endings, but that shouldn't matter as Java can cope with both Unix and Windows line endings.
     
  13. sk3pt1c thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #13
    ha, i was just about to type that :)

    yeah, the file was in UTF-16, as soon as i changed it to UTF-8, it worked fine :)

    thank you so much for helping out, it was a great opportunity for me to remember some of my java as well (reading through your source).

    Xcode seems like overkill for something this small so if i may ask another short question:
    how do you compile and run the source file in terminal?

    from what i remember we used to do a "javac file.java" and then "java file" or something like that... (but this was in '98 or something)

    :)
     
  14. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #14
    You are spot-on for compiling Java source: javac file.java then java file to run it.
     
  15. sk3pt1c thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #15
    once again kind sir, thank you!

    you are a credit to our race and a shinning example of what a member of these forums should be like! :)
     

Share This Page