0

I want to create an image with dynamic size like placeholder.com, below is the code to create image with golang:

width = 350
height = 150
img := image.NewRGBA(image.Rect(0, 0, width, height))
for x := 0; x < width; x++ {
    for y := 0; y < height; y++ {
        img.Set(x, y, color.RGBA{204, 204, 204, 1})
    }
}

Result:

enter image description here

But I want to draw the width x height the same as bellow:

enter image description here

I have researched but the results did not match my requirement. For example, this solution only draw text with fixed size and the text does not look sharp.

enter image description here

enter image description here

Jared Chu
  • 2,757
  • 4
  • 27
  • 38
  • 1
    Possible duplicate of [How to add a simple text label to an image in Go?](https://stackoverflow.com/questions/38299930/how-to-add-a-simple-text-label-to-an-image-in-go) – robbrit Apr 12 '18 at 03:09
  • It did not match my requirement – Jared Chu Apr 12 '18 at 03:23
  • I agree that the answer to the proposed duplicate should do what you want. Include the code that draws the text as well. – Peter Apr 12 '18 at 06:53
  • Sorry for not good at explanation. I didn't just ask about how to draw the text, it's about how to draw dynamic size text as sharp as placeholder.com. – Jared Chu Apr 12 '18 at 06:59
  • 1
    Try the second answer to the question in the above link. The library he uses allows you to specify the size of the typeface. You need to calculate the size based on the size of the output image. – dev.bmax Apr 12 '18 at 11:24
  • @dev.bmax Yeah I'm trying https://github.com/jaredchu/go-image-place-holder/commit/59defd8410a47b29df03d4f9380c478680b96f07 – Jared Chu Apr 13 '18 at 01:56

0 Answers0