How to create a graphic object without a border

I want to create a series of rectangles that contain different labels.

Graphics[{Rectangle[{0, 0}, {640, 480}], 
  Style[Text["Some text", {120, 50}], FontSize -> 24, 
   FontColor -> White]}]

The problem is that the rectangles are saved with a white border. It isn’t caused by EdgeForm[], because the white border is outside of the graphics object. Is there some other way of ensuring that the object has no border, or possibly setting the background colour to the same colour of the object.

Cheers
Andy

Maybe you can try the option PlotRangePadding -> None.

Hi Gianluca,
Thanks very much for your thought. I have revised my code, but the image still has a white background. I wonder if there is a way to trim the image after I generate it. Perhaps that’s a better approach.

Export["pic.png", 
 Graphics[{ Frame -> None, 
   ImagePadding -> None, Rectangle[{0, 0}, {640, 480}], 
   Style[Text["some text", {120, 50}], FontSize -> 24, 
    FontColor -> White]}]]

Cheers
Andy

Hi Andrew,

Adding PlotRangePadding -> None helps, but I still see a thin strip of white on the right and bottom edges.

Hi Rohit,
It is very strange, isn’t it. I can’t work out what is causing the problem.

My current code is:

Export["pic.png", 
 Graphics[{EdgeForm[{Thick, Green}], Frame -> None, 
   ImagePadding -> None, PlotRangePadding -> None, 
   Rectangle[{0, 0}, {640, 480}], 
   Style[Text["some text", {120, 50}], FontSize -> 24, 
    FontColor -> White]}]]

And that produces:

Although it isn’t clear, because the background of this forum is also white, there is definitely a 5px’ish border. When I import the image I can see it more clearly. I will try cropping it within MMA, and exporting the cropped image to try and work out if the problem is with Graphics[] or Export[] - which seems unlikely.

Cheers
Andy

Hey Andrew,

The options were specified in the same list as the primitives. That is what caused the issue. This works

Export["pix.png",
 Graphics[
  {
   Rectangle[{0, 0}, {640, 480}],
   Style[Text["some text", {120, 50}], FontSize -> 24, FontColor -> White]
  },
  Frame -> None,
  ImagePadding -> None,
  PlotRangePadding -> None]]

Rohit, you are a star!

Thanks so much.

Cheers,

Andy