|
|
|
|
@ -32,8 +32,8 @@ use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Intervention\Image\Facades\Image;
|
|
|
|
|
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
|
|
|
|
use function GuzzleHttp\Psr7\str;
|
|
|
|
|
use Kkokk\Poster\Facades\Html;
|
|
|
|
|
|
|
|
|
|
use Barryvdh\Snappy\Facades\SnappyImage;
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
|
|
|
|
class OrdersController extends CommonController
|
|
|
|
|
{
|
|
|
|
|
@ -1955,17 +1955,22 @@ class OrdersController extends CommonController
|
|
|
|
|
"errormsg" => "html内容不能为空"
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
$htmlObj = Html::load($html)->transparent()->size(338, 426)->render();
|
|
|
|
|
$file = $htmlObj->getFilePath();
|
|
|
|
|
dd($file);
|
|
|
|
|
$file = file_get_contents($file);
|
|
|
|
|
// $blob = $htmlObj->getImageBlob();
|
|
|
|
|
$base64 = base64_encode($file);
|
|
|
|
|
$options = [
|
|
|
|
|
'format' => 'png', // 图片格式 (png/jpg等)
|
|
|
|
|
// 'width' => 400, // 图片宽度
|
|
|
|
|
// 'height' => 200, // 图片高度
|
|
|
|
|
// 'quality' => 90 // 图片质量 (仅对jpg有效)
|
|
|
|
|
];
|
|
|
|
|
// 3. 生成图片二进制内容
|
|
|
|
|
$imageContent = SnappyImage::setOptions($options)->generateFromHtml($html);
|
|
|
|
|
|
|
|
|
|
// 4. 转换为Base64编码 (添加数据协议头)
|
|
|
|
|
$base64Image = 'data:image/' . $options['format'] . ';base64,' . base64_encode($imageContent);
|
|
|
|
|
return response()->json([
|
|
|
|
|
"errorcode" => "200",
|
|
|
|
|
"errormsg" => "html生成图片成功",
|
|
|
|
|
"errormsg" => "success",
|
|
|
|
|
"data" => [
|
|
|
|
|
"image_base64" => $base64
|
|
|
|
|
"base64_image" => $base64Image
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|