PhantomJSã§æ¥æ¬èªãæååããã¦è¾ã
PhantomJSã¯ç´ æµãªãã¼ã«ã§ãWebãµã¤ãã®ãã£ããã£ãç°¡åã«åã£ããã§ããã PhantomJSã使ã£ã¦Webãµã¤ãã®ã¹ãããã·ã§ãããåã便å©ãªã©ã¤ãã©ãªãæ¢ã«ããã¤ããã£ã¦ãä¾ãã°node-webshotã¨ããã£ããããã便å©ã
ãããªä¾¿å©ãªPhantomJSã ãã©ãLinuxä¸ã§åããã¨æ¥æ¬èªãã©ã³ããæååãããã±ã¼ã¹ããã°ãã°ãã£ã¦ãã¨ããã«è¦ããæãã«ãªãã å æ¥ãDebian Wheezyã§åãããã¨ãã¦å¤§å¤ãªæããããã®ã§ãããã¤ã試ãã¦ããã£ããã¨ãæ®ãã¦ããããã¨æãã ãã ãå®å ¨ã«ãã¾ãããæ¹æ³ã¯çµå±ããããªãã£ãã®ã§ã容赦é¡ãããããã£ã¨ããããã»ããããã®ã§ã¯ã¿ãããªã®ããã£ããæãã¦ã»ããã¨ããã
ãªããMacã ã¨ã ããããã¾ããããã©ã1.9.7ã使ãã¨Webãã©ã³ãã®æç»ãããããªæãã«ãªãã®ã§ã1.9.2ã¨ã使ãã®ãããã
PhantomJSãã¤ã³ã¹ãã¼ã«ããã®ã¯ãnpm
ã便å©ã
npm i [email protected]
å ã«èª¬æããéãã1.9.7ã ã¨Webãã©ã³ãã®æç»ããã¾ããããªãã®ã§ã1.9.2ã使ããä»å¾ã®ãã¼ã¸ã§ã³ã§ç´ãã¨å¬ããã
å¾ã¯ãexamplesã«å
¥ã£ã¦ããrasterize.js
ã使ã£ã¦ç°¡åã«ãã£ããã£ã試ããã¨ãã§ããã
./node_modules/.bin/phantomjs --ssl-protocol=any \ ./node_modules/phantomjs/lib/phantom/examples/rasterize.js \ https://encrypted.google.com/ capture.png
SSLã®ãµã¤ãããã£ããã£ããã«ã¯--ssl-protocol
ã§TLSã¨ããæå®ãããanyã使ããã®ã§ãã¨ããããanyã«ãã¦ããã°ããããããªããã¨æã£ã¦ãã
OSXã ã¨ããã§ååã§ããã¾ãæ¥æ¬èªã§ããã£ããã£ã¼ã§ãããã©ãåããã¨ãDebianã§ããã¨ã ããããè±è ã«ãªãã
æ¥æ¬èªãã©ã³ããå ¥ãã
å½ããåã ãã©ãæ¥æ¬èªãã©ã³ããå ¥ã£ã¦ããªãã¨æ¥æ¬èªãã¬ã³ããªã³ã°ã§ããªãã®ã§ãè±è ã«ãªãã
ããã©ã«ãã®ãã©ã³ãã¯dejavuãªã£ã¦ããã¯ããªã®ã§ãIPAãã©ã³ãã¨ããã®ããããå ¥ããã°ãããMigMixãããæãã ã£ãã
aptitude install fonts-migmix
ããã§æ¥æ¬èªãã©ã³ããã¤ã³ã¹ãã¼ã«ãããã
fc-match
ã¨ãã使ã£ã¦ç¢ºèªããã
fc-match 'sans-serif' migmix-2p-regular.ttf: "MigMix 2P" "Regular"
ããã§ãã¾ãæ¥æ¬èªã表示ããã幸ããªæ¹ã¯ã©ããã¼ã§ãã
font-configã®è¨å®ããã
æ¥æ¬èªãã©ã³ããã¤ã³ã¹ãã¼ã«ããã ãã§è§£æ±ºããã¨ãããã©ãä»åãã¾ããããªãã£ãã®ã§ãfont-confãããããã¨ã«ãªã£ãã
PhantomJSã¯font-configã使ã£ã¦ããã®ã§ã代æ¿ãã©ã³ãã®è¨å®ãããã¨ãããã¨æã£ããã©ããã¾ããããªãã£ãã
ãã©ã³ãã®è¨å®ã¯/etc/fonts
ã«ãã£ã¦ã/etc/fonts/fonts.conf
ã¨ãããããã¨ããããã§æ¤ç´¢ããã¨å¼ã£ããããã©ã
Debiançã«ã¯/etc/fonts/fonts.conf
ãç´æ¥è§¦ãã®ã¯ãã¡ãããã®ã§ã/etc/fonts/conf.avail
ã«ãã¡ã¤ã«ãç½®ãã¦/etc/fonts/conf.d
ã«ã·ã³ããªãã¯ãªã³ã¯ãç½®ãã¹ã¿ã¤ã«ã«ãããããã
ãããã¯ã/etc/fonts/local.conf
ãä½ã£ã¦ããããã$XDG_CONFIG_HOME/fontconfig/fonts.conf
ã§ãããã
fontfoncigã®è¨å®ãã¡ã¤ã«ã¯XMLã§ããã¨ãã°ãããªæãã«æ¸ãã
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <match target="pattern"> <test qual="any" name="family"> <string>serif</string> </test> <edit name="family" mode="assign" binding="strong"> <string>MigMix 2P</string> </edit> </match> </fontconfig>
ããã§serifã®ãã©ã³ããMigMixã«ã§ããã¯ãã ãã©ãèªåã®ç°å¢ã§ã¯ãã¾ãã§ããªãã£ãã®ã§ã次ã®æ¹æ³ã§å¯¾å¿ããã (PhantomJSãQTWebkitã使ã£ã¦ãããã¨ãåå ãããªããã¨çã£ã¦ãããã©ã調ã¹ããã¦ããªãã)
ãªãã69-language-selector-ja-jp.conf
ãªãã¦è¨å®ãããã®ã§ã試ãã¦ã¿ãã®ããããããããªãã
CSSãå ¥ãæ¿ãã
PhantomJSã«ã¯page.evaluateããã£ã¦ãä»»æã®JSãå®è¡ãããã¨ãã§ããã ãããå©ç¨ãã¦ããã¼ã¸ã®CSSãå ¥ãæ¿ãããã©ã³ããã·ã¹ãã ã«ã¤ã³ã¹ãã¼ã«ããã¦ãããã®ã«ãã¦ãã¾ãã
* { font-family: "MigMix 2P" }
ããã¯ãã ã®Workaroundã ãã©ãããã ãã§ãã¾ããããã¼ã¸ãå¤ããã©ããã¦ããã¡ãªã¨ãã«ã¯ä¾¿å©ã ã ãã ããã®æ¹æ³ã ã¨Webãã©ã³ãã®ç½®ãæããããã¦ãã¾ãã¨è¦ããã®ã§ãCSS3ã®notã»ã¬ã¯ã¿ã使ãã¨ä¾¿å©ã
ãæå¾ã«
workaroundã§ã¯ãªãæé«ã®è§£æ±ºæ¹æ³ãããã°èª°ãæãã¦ãã ããã
æ¨æ¥ãä»æ¥ããã£ã¨/etc/fontsã®ãã¡ã¤ã«ããã¡ããã¡ãããã£ã¦ã
— ã·ãªã«@æ¦å¿µ (@t_cyrill) 2014, 10æ 1
ã³ã³ã½ã¼ã«ãã°ã¯phantomjsã®å®è¡ãã°ã§ãã£ã±ãã ã200åãããã¯æã£ã¦ããã ããããphantomjsã®éçºè
ã¯ãã£ã¨ãã£ã±ãæã£ã¦ãããã ãããªãèªåã¯ã¡ããã
— ã·ãªã«@æ¦å¿µ (@t_cyrill) 2014, 10æ 1
ãã®ä»
- LANG="ja_JP.UTF8" ã ã¨ãã¡ã ã¨ããæ å ±ããããã©ãLANG=Cã§ããã¾ããããªãã£ãã®ã§ããããããªãã
- é©å¿ããããã©ã³ã以å¤ã
mv
ãããªã©ãã¦ã©ããã°ããã¨ããæ å ±ããã£ããã©ãfontconfigãé©ãããã©ã³ããè¦ã¤ããããçµæçã«ãããé¸ã°ããã ãã§ãããæ¹æ³ã§ã¯ãªãã¨æãã - ãã¨ãèªåã®ç°å¢ã§ã¯ãã®æ¹æ³ã§ããã¾ããããªãã£ãã®ã§ãä»ã®åå ãããããã
- ã¨ãããæªãã®ã¯fontconfigã§ã¯ãªãã®ãããããªãã
/etc/fonts/fonts.conf
ãæ¸ãæããç³»ã¯ããã¦ãããã»ããããããã®ãã¡ã¤ã«ã¯èªåçæããããã¡ã¤ã«ãªã®ã§ããã¤æ¸ãæãããããããªãã