在 Facebook 上分享 Dcard 文章時,如果沒有指定圖片的話,可能會看到如下的文章摘要:
這張圖片是透過 Go library draw2d 產生的,它有類似 HTML5 canvas 的 API,所以畫一些簡單的圖形都還算小菜一碟,然而在處理文字上就沒這麼得心應手了。
src, _ := loadBaseImageForPost(post)
在 Facebook 上分享 Dcard 文章時,如果沒有指定圖片的話,可能會看到如下的文章摘要:
這張圖片是透過 Go library draw2d 產生的,它有類似 HTML5 canvas 的 API,所以畫一些簡單的圖形都還算小菜一碟,然而在處理文字上就沒這麼得心應手了。
src, _ := loadBaseImageForPost(post)
(function(window){ | |
var cache = 0; | |
var scrollBarWidth = function(){ | |
if (cache) return cache; | |
var elem = document.createElement('div'); | |
elem.style.position = 'absolute'; | |
elem.style.top = '-9999px'; | |
elem.style.overflow = 'scroll'; |
func drawLine(gc *draw2dimg.GraphicContext, str string, maxX float64, maxY float64, x float64, y float64) (bool, float64) { | |
// Handle empty line | |
if len(strings.TrimSpace(str)) == 0 { | |
return false, y + gc.Current.FontSize*lineHeight | |
} | |
list := []rune(str) | |
length := len(list) | |
offsetX := x | |
offsetY := y |
func drawLine(gc *draw2dimg.GraphicContext, str string, maxX float64, maxY float64, x float64, y float64) (bool, float64) { | |
// Handle empty line | |
if len(strings.TrimSpace(str)) == 0 { | |
return false, y + gc.Current.FontSize*lineHeight | |
} | |
list := []rune(str) | |
length := len(list) | |
offsetX := x | |
offsetY := y |
func drawLine(gc *draw2dimg.GraphicContext, str string, x float64, y float64) { | |
gc.FillStringAt(str, x, y) | |
} | |
func drawText(gc *draw2dimg.GraphicContext, str string, width float64, height float64, x float64, y float64) { | |
str = strings.Trim(str, " \n\r\t") | |
lines := strings.Split(str, "\n") | |
fontSize := gc.Current.FontSize | |
offsetY := y | |
wrapLines := []string{} |
draw2d.SetFontFolder("static/fonts") | |
draw2d.SetFontNamer(func(fontData draw2d.FontData) string { | |
return "WenQuanYiMicroHei.ttf" | |
}) |
2016/11/04 16:06:16 open ../resource/font/luxisr.ttf: no such file or directory | |
2016/11/04 16:06:16 open ../resource/font/luxisr.ttf: no such file or directory | |
2016/11/04 16:06:16 No font set, and no default font available. |
src, _ := loadBaseImageForPost(post) | |
img := image.NewRGBA(src.Bounds()) | |
gc := draw2dimg.NewGraphicContext(img) | |
gc.DrawImage(src) | |
// Draw title | |
gc.SetFillColor(color.RGBA{0xff, 0xff, 0xff, 0xff}) | |
gc.SetFontSize(26) | |
gc.FillStringAt(post.Title, 140, 81.5) |
import java.util.*; | |
public class s401631741HW1 { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("i = "); | |
int number = scanner.nextInt(); | |
Random random = new Random(); | |
int[][] arr = new int[number][]; |
hexo.extend.console.register('gzip', function(args, callback){ | |
hexo.call('generate', function(err){ | |
if (err) return callback(err); | |
// do gzip here... | |
}); | |
}); |