javascript - 无法在 PHP 函数中使用 RGB 设置透明度
问题描述
在函数中使用 rgb 格式时不能使用透明度:
"message": "无法读取颜色 rgb(0 0 1 / 50%)。"
如果我使用像#ffff 或#000 这样的普通颜色,它会起作用。
我正在使用此功能在图像上添加文本水印。:
public static function addwatermark( $name ) {
$thumbnail = Image::make($name);
$thumbnail->text('WATERMARKTEXT', 90, 50, function ($font) use ($thumbnail) {
$font->file('public/watermarkfont.ttf');
$font->color(rgb(0 0 1 / 50%));
});
$thumbnail->save($name)->destroy();
}
参考:https ://onlinewebtutorblog.com/how-to-add-watermark-text-on-images-laravel-8/
解决方案
问题是您试图在rgb()
要使用时添加不透明度rgba()
,它具有处理不透明度的 alpha 通道。
public static function color_inverse($color){
$color = str_replace('#', '', $color);
if ($color == '000000'){
return "rgba(255, 255, 255, 1)";
}
return "rgba(0, 0, 0, 0.5)";
}
在这里,您可以找到文档color
中水印方法可用的所有格式。
不透明度从1
到0
,1
为 100%,0
为 0%,因此0.5
为 50% 的不透明度。
推荐阅读
- python - 如何在 python 中绘制 CSV 文件的单个柱形图?
- java - Intellij Ultimate:Spring Boot 应用程序不在正常模式下获取 Web 资源,而是在 mvn spring-boot:run 中获取
- python - Keras Double DQN 平均奖励随时间递减且无法收敛
- html - 过滤前隐藏引导表
- c# - 如何在表单应用程序的 WebBrowser 控件中的 HTML 元素的鼠标悬停时显示弹出窗口
- c# - 未使用依赖注入处理 DbContext
- javascript - v-autocomplete 如何检测是否没有结果并添加自定义操作
- node.js - Electron 错误 ENOENT:没有这样的文件或目录,打开 'electron' 从 9 更新到 10 后
- android - 如果我使用反向布局,最近的聊天会显示在聊天屏幕的顶部。如何在输入框上方底部显示最近的消息。(如 wapp)
- c# - “使用范围运算符”建议的修复会产生无效代码