java HTML轉(zhuǎn)圖片

原先使用過(guò)wkhtmltox,也是個(gè)不錯(cuò)的工具,使用也是相當(dāng)簡(jiǎn)單,不過(guò)對(duì)部分css3樣式不支持

現(xiàn)在使用Chrome CLI生成圖片,就是安裝瀏覽器,利用瀏覽器生成圖片,只要瀏覽器能解析,生成圖片就是ok的
參看下https://blog.csdn.net/xuechangchun007/article/details/120936431

安裝

yum install -y chromium

測(cè)試

chromium-browser --no-sandbox --headless --screenshot=test.png -run-all-compositor-stages-before-draw --window-size=1280,1400 test.html

[root@xxxxxxxxxxx~]# chromium-browser --no-sandbox --headless --screenshot=test.png -run-all-compositor-stages-before-draw --window-size=1280,1400 test.html 
[0726/152136.525841:ERROR:angle_platform_impl.cc(43)] Display.cpp:977 (initialize): ANGLE Display::initialize error 12289: Could not open the default X display.
[0726/152136.526057:ERROR:gl_surface_egl.cc(852)] EGL Driver message (Critical) eglInitialize: Could not open the default X display.
[0726/152136.528157:WARNING:bluez_dbus_manager.cc(248)] Floss manager not present, cannot set Floss enable/disable.
[0726/152136.528073:ERROR:gl_surface_egl.cc(1489)] eglInitialize Default failed with error EGL_NOT_INITIALIZED
[0726/152136.528639:ERROR:gl_ozone_egl.cc(21)] GLSurfaceEGL::InitializeOneOff failed.
[0726/152136.539316:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0726/152136.563806:ERROR:angle_platform_impl.cc(43)] Display.cpp:977 (initialize): ANGLE Display::initialize error 12289: Could not open the default X display.
[0726/152136.564481:ERROR:gl_surface_egl.cc(852)] EGL Driver message (Critical) eglInitialize: Could not open the default X display.
[0726/152136.564527:ERROR:gl_surface_egl.cc(1489)] eglInitialize Default failed with error EGL_NOT_INITIALIZED
[0726/152136.564565:ERROR:gl_ozone_egl.cc(21)] GLSurfaceEGL::InitializeOneOff failed.
[0726/152136.573258:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0726/152136.586732:ERROR:angle_platform_impl.cc(43)] Display.cpp:977 (initialize): ANGLE Display::initialize error 12289: Could not open the default X display.
[0726/152136.586854:ERROR:gl_surface_egl.cc(852)] EGL Driver message (Critical) eglInitialize: Could not open the default X display.
[0726/152136.586995:ERROR:gl_surface_egl.cc(1489)] eglInitialize Default failed with error EGL_NOT_INITIALIZED
[0726/152136.587080:ERROR:gl_ozone_egl.cc(21)] GLSurfaceEGL::InitializeOneOff failed.
[0726/152136.589127:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0726/152136.596440:ERROR:gpu_init.cc(481)] Passthrough is not supported, GL is disabled, ANGLE is 

有報(bào)錯(cuò),不過(guò)生成的圖片是ok的

接下來(lái)就是java執(zhí)行命令命令行,然后讀取圖片,業(yè)務(wù)邏輯就自行處理了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容