diff --git a/image_utils.go b/image_utils.go index f5c3fe3..0796179 100644 --- a/image_utils.go +++ b/image_utils.go @@ -733,11 +733,14 @@ func drawShapedBlockAt( func drawImageAt(img draw.Image, imageUrl string, startY int) int { resp, err := http.Get(imageUrl) if err != nil { - return startY + return -1 } defer resp.Body.Close() srcImg, _, err := image.Decode(resp.Body) + if err != nil { + return -1 + } // Resize the fetched image to fit the width of the destination image (img) width := img.Bounds().Dx() @@ -756,13 +759,16 @@ func drawVideoAt(img draw.Image, videoUrl string, startY int) int { cmd.Stdout = nil cmd.Stderr = nil if err := cmd.Run(); err != nil { - return startY + return -1 } frame, _ := os.Open(tempImagePath) defer os.Remove(tempImagePath) defer frame.Close() - imgData, _, _ := image.Decode(frame) + imgData, _, err := image.Decode(frame) + if err != nil { + return -1 + } width := img.Bounds().Dx() resizedFrame := resize.Resize(uint(width), 0, imgData, resize.Lanczos3) diff --git a/render_image.go b/render_image.go index 8c7459e..76b8b28 100644 --- a/render_image.go +++ b/render_image.go @@ -217,8 +217,15 @@ func drawParagraphs(paragraphs []string, fontSize int, width, height int) (image if i == 0 { yPos = 0 } - yPos = drawMediaAt(img, paragraph, yPos) - continue + next := drawMediaAt(img, paragraph, yPos) + if next != -1 { + yPos = next + // this means the media picture was successfully drawn + continue + } + + // if we reach here that means we didn't draw anything, so proceed to + // draw the text } rawText := []rune(paragraph)