mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 14:24:27 +01:00
cleaner failures when media fails to load or draw.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -217,10 +217,17 @@ func drawParagraphs(paragraphs []string, fontSize int, width, height int) (image
|
||||
if i == 0 {
|
||||
yPos = 0
|
||||
}
|
||||
yPos = drawMediaAt(img, paragraph, yPos)
|
||||
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)
|
||||
|
||||
shapedRunes, emojiMask, hlMask := shapeText(rawText, fontSize)
|
||||
|
||||
Reference in New Issue
Block a user