# Save image by input name as jpg or to absolute path

**URL:** <https://discourse.processing.org/t/save-image-by-input-name-as-jpg-or-to-absolute-path/8674>\
**Category:** Coding Questions\
**Created:** [February 24, 2019, 2:33am UTC](https://discourse.processing.org/t/save-image-by-input-name-as-jpg-or-to-absolute-path/8674 "2019-02-24T02:33:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![angelman](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@angelman](https://discourse.processing.org/u/angelman)\
**Post date:** [February 24, 2019, 2:33am UTC](https://discourse.processing.org/t/save-image-by-input-name-as-jpg-or-to-absolute-path/8674/1 "2019-02-24T02:33:28Z")

</div>

I am inputting a list of names and output images made as result of list of names. This works fine . It will out put them as tif . But how can I get them output as jpg. and also to a folder in the sketch folder rather than the sketch folder itself. Lines 98 99 100.

```auto
   //This now adds the rates to the pic;
    int[] colorLines;
    int[] red;
    int[] green;
    int[] blue;
   int n;
   int r1;
   int g1;
   int b1;
     
    String[] lines;
     String l;
    
    void setup(){
      size(400,200);}
      
void draw() {
  listOfRates();
 

noLoop();
 
}
void listOfRates(){
  int[] colorLines = new int [400];
    int[] red = new int [400];;
    int[] green =new int [400];;
    int[] blue =new int [400];
    PGraphics pg;
  
  String[] lines = loadStrings("listin.txt");
 
  println("there are " + lines.length + " lines");

   for (int i = 0 ; i < lines.length;) 
   {
      String line= lines[i];
       String[] linesrates = split(line,' ');
       String last = linesrates[linesrates.length-1];
       String[] notlast = shorten(linesrates);
       String first = join(notlast," ");
      println(line); 
      println(last);
      println(first);
      
    
 pg = createGraphics(400,200);
    pg.beginDraw();
      // Populate the colorlines with widths .
      for( int k=0; k < colorLines.length; k++)
      { 
        strokeCap(SQUARE);
   
         int sW = int(random(20,40));
        //strokeWeight(sW);       
      colorLines[k] = sW;
      }
      //Make each line.
      for( int m = 0; m < 400; m+=16 )
      {
    // Give each line a random color and width each time it's drawn.
  

   float r = int(random(255));

    red[m]=int(r);
  
    float g = int(random(255));
    
    green[m] = int(g);
    float b = int(random(255));

    blue[m] = int(b);//blue
      }
          

   //pg = createGraphics(400,200);
    //pg.beginDraw();
    for (int j = 0; j < 400; j += 16 )
  { 
  strokeWeight(colorLines[j]);
   stroke(red[j],green[j],blue[j]);
   line(j, 0, j , 200); 
  //put input on top of colorcode
  }
     textSize(26);
     fill(255,255,255);
      text(first,50,50);
      textSize(10);
    text("AM", 365, 185);
     textSize(14);
    text("rate = " + last, 50, 185);
     pg.endDraw();
     
      PImage partialSave = get(0,0,400,200);
     
       partialSave.save(line);
    
   
    println("screenshot saved");

    //text("done",10,20);
    
    i++;
}//noLoop();
return;
}
```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [February 24, 2019, 3:00am UTC](https://discourse.processing.org/t/save-image-by-input-name-as-jpg-or-to-absolute-path/8674/2 "2019-02-24T03:00:25Z")

</div>

give a name and pls  
use “data/filename”  
for load and save!!!

the default load reads from data/  
the default save writes to sketch path  
that is more confusing as it helps.  
so use path and filename.

```auto
/**
 * Load and save 
 */
PImage img, part;
void setup() {
  size(640, 360);
  img = loadImage("data/moonwalk.jpg"); 
  part = img.get(0,0,width/2,height/2);
  part.save("data/get_top_left.jpg");
  exit();
}

//void draw() {}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 24, 2019, 3:09am UTC](https://discourse.processing.org/t/save-image-by-input-name-as-jpg-or-to-absolute-path/8674/3 "2019-02-24T03:09:12Z")

</div>

> [@angelman](#):
>
> And also to a folder in the sketch folder rather than the sketch folder itself.

Pass the filename’s String as an argument for **dataPath()**: 📂

`partialSave.save(dataPath(line));`

---

<div class="post-metadata">

**Author:** ![angelman](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@angelman](https://discourse.processing.org/u/angelman)\
**Post date:** [February 24, 2019, 3:36am UTC](https://discourse.processing.org/t/save-image-by-input-name-as-jpg-or-to-absolute-path/8674/4 "2019-02-24T03:36:30Z")

</div>

thanks Learned something there. But how to save as jpg. in my sketch the input is loadStrings and out put is Images with the stringname.(that is input).

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [February 24, 2019, 4:06am UTC](https://discourse.processing.org/t/save-image-by-input-name-as-jpg-or-to-absolute-path/8674/5 "2019-02-24T04:06:52Z")

</div>

i have no idea what is the content of String line  
( you not show the file or the console print )  
but you can do like:

```auto
String saveto,line;

  line = "picname";
  saveto = "data/"+line+".jpg";
  part.save(saveto);

```

even:

```auto
String saveto,line;
int p;

  line = "picname";
  p++;
  saveto = "data/"+line+"_"+p+".jpg";
  println(saveto);
  part.save(saveto);

```

---

<div class="post-metadata">

**Author:** ![angelman](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@angelman](https://discourse.processing.org/u/angelman)\
**Post date:** [February 24, 2019, 4:30am UTC](https://discourse.processing.org/t/save-image-by-input-name-as-jpg-or-to-absolute-path/8674/6 "2019-02-24T04:30:55Z")

</div>

yep. that works. great thanks But I dont understand this line; ```  
saveto = “data/”+line+".jpg";

```auto

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [February 24, 2019, 4:32am UTC](https://discourse.processing.org/t/save-image-by-input-name-as-jpg-or-to-absolute-path/8674/7 "2019-02-24T04:32:18Z")

</div>

play with it and print it, so you can learn, like

```auto
saveto = "data/"+line+"_"+p+".jpg";

```

constructs a path/filename from strings, string variables and integer( like counter )  
i think its easy to understand, if you need it i don’t know? as i am still guessing  
about your code.
