Specifying dpi of saved images

Hello all,

I need to prepare some figures for a publication that requires 600 dpi jpeg images. Does anyone know how I can specify a specific dpi setting when saving a jpeg file of the canvas?

Thanks,
Curtis

Hi,
it is not possible to specify dpi of saved jpeg image (I might be wrong).
The default resolution of saved jpeg image is 72 dpi.
ROOT canvas graphics is in pixel units.
To create 600 dpi jpeg (take, as an example, hsimple.C from tutorials)
with the same print size as original 72 dpi image:

  1. edit hsimple.C code to create a large canvas scaled by the factor of 600./72. = 8.33
// Create a new canvas.
  c1 = new TCanvas("c1","Dynamic Filling Example",200,(UInt_t)700*8.33,(UInt_t)500*8.33);
  1. execute hsimple.c macro in batch mode
root -b
root[1].x tutorials/hsimple.C
  1. create jpeg image
 root[2]c1->Print("600dpi.jpg");
  1. output 600dpi.jpg file can be editted with PhotoShop or Gimp, which allows to convert it
    to 600dpi print resolution jpeg file.
  • another way to create 600dpi jpeg is :
    o save canvas as PostScript or PDF file
    o use GhostScript to convert it to 600 dpi JPEG.

HTH. Valeriy

++
I hope we will revisit this problem on the road of the development of TImage/TASImage classes.

Hi Valeriy,

I will try the different methods you mentioned.

Thanks,
Curtis

Hi Curtis,
you can change the DPI setting of existing jpeg file (without using Gimp or PhotoShop)
with the following macro:

#include <stdio>

void chdpi(const char *name, int set = 600)
{
   // set dpi resolution to jpeg image file

   char buf[20];
   FILE *fp = fopen(name, "rb+");
   fread(buf, 1, 20, fp);

   char dpi1 = (set & 0xffff) >> 8;
   char dpi2 = set & 0xff;

   int i = 0;

   int dpi = 0; // start of dpi data
   for (i = 0; i < 20; i++) {
      if ((buf[i] == 0x4a) && (buf[i+1] == 0x46) &&  (buf[i+2] == 0x49) &&  
          (buf[i+3] == 0x46) && (buf[i+4] == 0x00) ) {
         dpi = i + 7;
         break;         
      }
   }

   if (i == 20) { // not found
      fclose(fp);
      printf("file %s : wrong JPEG format\n", name);
      return;
   }

   buf[dpi] = 1;   // format is dots per inch

   // set x density in dpi units
   buf[dpi + 1] = dpi1;
   buf[dpi + 2] = dpi2;

   // set y density in dpi units
   buf[dpi + 3] = dpi1;
   buf[dpi + 4] = dpi2;

   rewind(fp);
   fwrite(buf, 1, 20, fp);
   fclose(fp);
}

An example of usage:

root[].L chdpi.C
root[]chdpi("myfile.jpg", 600)

I added an auxilary static method to TASImage class
Bool_t TASImage::SetJpegDpi(const char *name, UInt_t dpi = 72)

Must be in CVS asap.

Regards. Valeriy