Group Abstract Group Abstract

Message Boards Message Boards

0
|
5K Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How to create a graphic object without a border

Posted 4 years ago

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

POSTED BY: Andrew Burnett
6 Replies
Posted 4 years ago

Rohit, you are a star!

Thanks so much.

Cheers,

Andy

POSTED BY: Andrew Burnett
Posted 4 years ago

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: enter image description here

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

POSTED BY: Andrew Burnett
Posted 4 years ago

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]]
POSTED BY: Rohit Namjoshi
Posted 4 years ago

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

POSTED BY: Andrew Burnett
Posted 4 years ago

Hi Andrew,

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

POSTED BY: Rohit Namjoshi

Maybe you can try the option PlotRangePadding -> None.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard