Skip to content

Instantly share code, notes, and snippets.

@equivalent
Created July 1, 2020 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save equivalent/27d4abbb78ea991778316526f87fff94 to your computer and use it in GitHub Desktop.
Save equivalent/27d4abbb78ea991778316526f87fff94 to your computer and use it in GitHub Desktop.
wkhtmltoimage / IMGKit gem UTF-8 test of Chinese and Arabic characters
# IMGKit lib is a Ruby wrapper around wkhtmltoimage
#
# * https://github.com/csquared/IMGKit
# * https://wkhtmltopdf.org/
#
class Html2image
def call
head = '<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>'
div = "<div class='ping'>Pong 读写汉字 - 学中文 ... ﺩ ﻁ ﺽ ﻙ ﻕ. ﻑ ﺙ ﺱ ﺹ ﺵ چ ﺥ ﺡ ﻩ. ڤ ﺫ ﺯ ﻅ ﺝ ﻍ ﻉ ﺓ. ﻡ ﻥ. ﻭ ﻝ ﺭ ﻱ ﻯ. ﺀ ﺃ ﺇ ﺅ ﺉ. ـِﻳ ـِ ـٍ. ـُﻭ ـُ ـٌ. ـَﺍ ✅</</div>" # randomly googled Chinese and Arabic characters, I have no idea what they mean
html = '<html>' + head +'<body><h1>Abc</h1><p>test</p>' + div +'</body></html>'
kit = IMGKit.new(html, :quality => 50)
file = kit.to_file('/tmp/file.jpg')
end
end
# Html2image.new.call
@equivalent
Copy link
Author

equivalent commented Jul 7, 2020

Limit Height / Width

IMGKit.new(html, quality: 50, width: 600, height: 800)

file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment