# How to specify output size

**URL:** https://discourse.processing.org/t/how-to-specify-output-size/14711
**Category:** Coding Questions
**Created:** [October 15, 2019, 12:50pm UTC](https://discourse.processing.org/t/how-to-specify-output-size/14711 "2019-10-15T12:50:42Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mikemcsharry](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mikemcsharry](https://discourse.processing.org/u/mikemcsharry)
#### Post date: [October 15, 2019, 12:50pm UTC](https://discourse.processing.org/t/how-to-specify-output-size/14711/1 "2019-10-15T12:50:42Z")

</div>

I’m probably staring at the obvious answer but can’t see it.  
Down below id the simple code I’ve put together that reads this simple list and then creates a folder based on the contents of the list, in the folder is another folder which has one file which contains the event date / age group / location as a jpeg. it’s pretty much working as I intend, except it only writes the output image at a size of 100\*100. I’ve tried many ways o specify an image size, I’m even loading a starting image of quite a large size.  
Please can anyone let me know which bit of code I need to add, and where, so I can make the output as I want?  
Here is the input text file…

> October 2019  
> On course  
> Finish Straight  
> Yr3-Girls  
> Yr3-Boys  
> Yr4-Girls  
> Yr4-Boys  
> Yr5-Girls  
> Yr5-Boys  
> Yr6-Girls  
> Yr6-Boys  
> Yr7-Girls  
> Yr7-Boys

And here is the code.

```auto
PImage img; // Declare variable "a" of type PImage
String entry; // this is used for folder name
String outfile; //this is used for jpeg extension
String eventdate;
String location1;
String location2;
String filepath;
String quotemark = "\"";
String backslash = "/";
PFont f = createFont("Arial",16,true);
PGraphics pg;

String[] lines = loadStrings("textinput");
//println("there are " + lines.length + " lines");
eventdate = lines[0];
location1 = lines [1];
location2 = lines[2];
for (int i = 3 ; i < lines.length; i++) {
  
  entry = lines[i];
  
  outfile = entry + ".jpg";
  filepath = "banners";
  filepath=filepath + backslash + entry + backslash + outfile;
 // println(filepath);
// save(filepath);
// now we have created the file why not open it, add text and save it again
// problem is that everything being saved at 100*100

// repeat the code below for no location eg seniors and 2 locations

img = loadImage("blank2.JPG");
//img = createImage(4000,4000,RGB);
image (img,0,0);
text (eventdate,10,15);
text (entry,10,70);
save (filepath);
//group above got the no location
//now for 'on course'
outfile = entry + "on-course.jpg";
  filepath = "banners";
  filepath=filepath + backslash + outfile + backslash + outfile;
 // println(filepath);
// save(filepath);
// now we have created the file why not open it, add text and save it again
// problem is that everything being saved at 100*100

// repeat below for no location eg seniors and 2 locations
img = loadImage("blank2.JPG");
//img = createImage(4000,4000,RGB);
image (img,0,0);
text (eventdate,10,15);
text (entry,10,50);
text(location1,10,70);
save (filepath);

//now for finishing straight
outfile = entry + "straight.jpg";
  filepath = "banners";
  filepath=filepath + backslash + outfile + backslash + outfile;
  println(filepath);
// save(filepath);
// now we have created the file why not open it, add text and save it again
// problem is that everything being saved at 100*100

// repeat below for no location eg seniors and 2 locations
img = loadImage("blank2.JPG");
//img = createImage(4000,4000,RGB);
image (img,0,0);
text (eventdate,10,15);
text (entry,10,50);
text(location2,10,70);
save (filepath);

}

```

---

<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: [October 15, 2019, 1:07pm UTC](https://discourse.processing.org/t/how-to-specify-output-size/14711/2 "2019-10-15T13:07:35Z")

</div>

```auto
save()

```

is used to save the canvas,  
yours is the default 100\*100

as you not use

```auto
String outfile = "data/myCanvas.jpg";

void setup() {
  size(500,500);
}

void draw(){}

void keyPressed() {
  if ( key == 's' ) save(outfile);
}

```

what gives a 500\*500 empty picture.  
but wait:  
you could try

```auto
String outfile1 = "data/myCanvas.jpg";
String outfile2 = "data/img.jpg";
String infile = "data/moonwalk.jpg";
PImage img;

void setup() {
  size(500,500);
  img = loadImage(infile);
}

void draw(){
  //image(img,0,0);
}

void keyPressed() {
  if ( key == 's' ) save(outfile1); // canvas
  if ( key == 'c' ) img.save(outfile2); // copy img
}

```

what gives here a copy 640\*360 but smaller in kB ( jpg compression?)

---

<div class="post-metadata">

### Author: ![mikemcsharry](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mikemcsharry](https://discourse.processing.org/u/mikemcsharry)
#### Post date: [October 15, 2019, 1:24pm UTC](https://discourse.processing.org/t/how-to-specify-output-size/14711/3 "2019-10-15T13:24:41Z")

</div>

Hello kll,  
Thank you for the ideas there, I have been trying similar approaches with various error messages. ‘unexpected tokens’ ‘end of file’ and other errors.  
It seems absolutely right that it’s a default size issue.  
In my code, where would you add either of the suggestions you’ve posted  
Many thanks  
Mike

---

<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: [October 15, 2019, 1:30pm UTC](https://discourse.processing.org/t/how-to-specify-output-size/14711/4 "2019-10-15T13:30:13Z")

</div>

```auto
// save (filepath);
img.save(filepath);

```

test  
i understand that that would copy one picture to a other location

but please why not restart your project  
and make a good processing setup  
incl a show on the canvas…

---

<div class="post-metadata">

### Author: ![mikemcsharry](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mikemcsharry](https://discourse.processing.org/u/mikemcsharry)
#### Post date: [October 15, 2019, 1:34pm UTC](https://discourse.processing.org/t/how-to-specify-output-size/14711/5 "2019-10-15T13:34:11Z")

</div>

That’s a fair comment about the ‘show’ - however, this is one of those tasks that I really just want to create the folders and files as simply and rapidly as possible.  
[Processing.org](http://Processing.org) is doing a remarkable job, it would be really something to get the image size to a size I specify.  
I’'l try your latest suggestion, thank you for your help :)🙂

---

<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: [October 15, 2019, 1:37pm UTC](https://discourse.processing.org/t/how-to-specify-output-size/14711/6 "2019-10-15T13:37:23Z")

</div>

> [@mikemcsharry](#):
>
> to get the image size to a size I specify.

no problem,  
between

```auto
img = loadImage(infile);
// here
img.save(outfile);

```

can use

> **[resize() / Reference](https://processing.org/reference/PImage_resize_.html)**
>
> Resize the image to a new width and height. To make the image scale proportionally, use 0 as the value for the wide or high parameter. For instance, to make the width of an image 150 pix…

example:

```auto
String outfile1 = "data/myCanvas.jpg";
String outfile2 = "data/img.jpg";
String outfile3 = "data/imgnewsize.jpg";
String infile = "data/moonwalk.jpg";
PImage img;

void setup() {
  size(500,500);
  img = loadImage(infile);
}

void draw(){
  //image(img,0,0);
}

void keyPressed() {
  if ( key == 's' ) save(outfile1);
  if ( key == 'c' ) img.save(outfile2);
  if ( key == 'r' ) {
    img.resize((int)(img.width*2),(int)(img.height*2) );
    img.save(outfile3);
  }
}

```

---

<div class="post-metadata">

### Author: ![mikemcsharry](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mikemcsharry](https://discourse.processing.org/u/mikemcsharry)
#### Post date: [October 15, 2019, 1:52pm UTC](https://discourse.processing.org/t/how-to-specify-output-size/14711/7 "2019-10-15T13:52:51Z")

</div>

Thank you so much for your help, I will try that later today or tonight

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [October 15, 2019, 5:57pm UTC](https://discourse.processing.org/t/how-to-specify-output-size/14711/8 "2019-10-15T17:57:35Z")

</div>

Hello,

This was my morning programming exercise! Thanks!

I made a few changes to test the code and quality of output.

You can use PGraphics which does not depend on size of canvas.  
I had to add setup() for PGraphics and I only added draw() to display “Done!”.  
I provided a template for that; you may add the ? to complete if you wish.

Reference:  
[https://processing.org/reference/PGraphics.html](https://processing.org/reference/PGraphics.html)

```auto
//https://discourse.processing.org/t/how-to-specify-output-size/14711

  String entry; // this is used for folder name
  String outfile; //this is used for jpeg extension
  String eventdate;
  String location1;
  String location2;
  String filepath;
  String quotemark = "\"";
  String backslash = "/";
  PImage img;
  int count = 3;
  int w = 1000;
  int h = 400;
  
  PGraphics pg;

void setup()
  {
  size(1000, 400);
  fill(0);
  textAlign(CENTER);
  textSize(96);
  
  String[] lines = loadStrings("textinput");
  logo();
  
  pg = createGraphics(1000, 400);
  //pglogo();
  }
  
void draw()
  {
  background(255, 0, 0);
  text("Done!", width/2, height/2);
  noLoop();
  }    

void logo()
  {
  String[] lines = loadStrings("textinput");
  eventdate = lines[0];
  location1 = lines[1];
  location2 = lines[2];  
    
  for (int i = 3; i < lines.length; i++) 
    {
    background(255);
    entry = lines[i];
    
    outfile = entry;
    filepath = "banners";
    filepath=filepath + backslash + entry + backslash + outfile;
    text (eventdate + "\n\r" + entry + "\n\r", width/2, 150);
    
    save(filepath + ".gif");
    save(filepath + ".jpg");
    save(filepath + ".png");
    }
  }
  
/*
void pglogo()
  {
  String[] lines = loadStrings("textinput");
  eventdate = lines[0];
  location1 = lines[1];
  location2 = lines[2];  
    
  for (int i = 3; i < lines.length; i++) 
    {
    background(255);
    entry = lines[i];
    
    outfile = entry;
    filepath = "pgbanners";
    filepath=filepath + backslash + entry + backslash + outfile;
    
    pg.beginDraw();
    pg.background(?);
    pg.fill(?);
    pg.textSize(?);
    pg.textAlign(?);
    pg.text (?);
    pg.endDraw();
    
    pg.save(?);
    pg.save(?);
    pg.save(?);
    
    //image(pg, 0, 0);
    }
  }
*/

```

File sizes same for both versions:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7a3031a0682fd2094675e97743c3df877b0f02cb.png)

I suggest using PNG (my first choice) or GIF for this example; JPG has lossy compression and in this case a larger file.  
A search for “jpg vs gif vs png” will discuss this topic.

🙂

---

<div class="post-metadata">

### Author: ![mikemcsharry](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mikemcsharry](https://discourse.processing.org/u/mikemcsharry)
#### Post date: [October 15, 2019, 8:20pm UTC](https://discourse.processing.org/t/how-to-specify-output-size/14711/9 "2019-10-15T20:20:19Z")

</div>

I am absolutely astounded at the help and support on this forum - I use a few facebook groups which are full of kind and helpful people, but you good folks are truly, truly amazing and I am so grateful for your help!!
