osclass增加支持webp格式

ops/2025/2/11 14:53:24/

1、basic_data.sql

数据表:t_preference中的('osclass', 'allowedExt', 'png,gif,jpg,jpeg', 'STRING'),添加:'png,gif,jpg,jpeg,webp'

2、includes/osclass/mimes.php

'webp' => 'image/webp',

3、includes/osclass/classes/ImageProcessing.php

修改private function __construct($imagePath) {}

switch (@$this->image_info['mime']) {case 'image/gif':$this->ext = 'gif';$this->mime = 'image/gif';break;case 'image/png':$this->ext = 'png';$this->mime = 'image/png';break;case 'image/webp': // 增加 WebP 处理$this->ext = 'webp';$this->mime = 'image/webp';break;default:$this->ext = 'jpg';$this->mime = 'image/jpeg';if (!$this->_use_imagick) {$bg = imagecreatetruecolor($this->_width, $this->_height);// 处理 PNG、WebP 透明背景if (in_array($this->ext, ['png', 'webp'])) {imagefill($bg, 0, 0, imagecolorallocatealpha($bg, 0, 0, 0, 127));imagesavealpha($bg, true);imagealphablending($bg, false);} else {imagefill($bg, 0, 0, $this->imageColor($bg));imagesavealpha($bg, true);imagealphablending($bg, true);}imagecopy($bg, $this->im, 0, 0, 0, 0, $this->_width, $this->_height);imagedestroy($this->im);$this->im = $bg;}break;}

4、savetofile改成

public function saveToFile($imagePath, $ext = null) {if (file_exists($imagePath) && !is_writable($imagePath)) {throw new RuntimeException("$imagePath is not writable!");}if ($ext == null) {$ext = $this->ext;}// 允许 webp 格式if (!in_array($ext, ['png', 'gif', 'webp'])) {$ext = 'jpeg'; // 默认 jpeg}//var_dump($ext);if ($this->_use_imagick) {if ($ext === 'jpeg' && ($this->ext !== 'jpeg' && $this->ext !== 'jpg')) {$bg = new Imagick();$bg->newImage($this->_width, $this->_height, osc_canvas_background());$this->im->thumbnailImage($this->_width, $this->_height, true);$bg->compositeImage($this->im, Imagick::COMPOSITE_OVER, 0, 0);$this->im = $bg;$this->ext = 'jpeg';}$this->im->setImageDepth(8);$this->im->setImageFilename($imagePath);$this->im->setImageFormat($ext);$this->im->writeImage($imagePath);} else {switch ($ext) {case 'gif':imagegif($this->im, $imagePath);break;case 'png':imagepng($this->im, $imagePath, 0);break;case 'webp': // 增加 WebP 处理if (function_exists('imagewebp')) {//var_dump($ext);var_dump('oka');die;imagewebp($this->im, $imagePath);} else {//var_dump($ext);var_dump('okb');die;throw new RuntimeException("WebP format is not supported by GD");}break;default:if (($ext === 'jpeg' && ($this->ext !== 'jpeg' && $this->ext !== 'jpg')) || $this->_watermarked) {$this->ext = 'jpeg';}imagejpeg($this->im, $imagePath);break;}}}


http://www.ppmy.cn/ops/157549.html

相关文章

ffmpeg基本用法

一、用法 ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}... 说明: global options:全局选项,应用于整个 FFmpeg 进程,它们通常不受输入或输出部分的限制。 infile options:输入选…

Spring模块组成

一、Spring模块 Spring 总共大约有 20 个模块, 由 1300 多个不同的文件构成。 而这些组件被分别整合在核心容器(Core Container) AOP(Aspect Oriented Programming) 设备支持(Instrmentation) …

HTML之CSS定位、浮动、盒子模型

HTML之CSS定位、浮动、盒子模型 定位 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document<…

Kafka的架构解析

目录 1 背景2 kafka的架构来源2.1 增加消息队列2.2 高性能2.3 高可用2.4 持久化和过期策略2.5 Consumer Group2.6 Zookeeper 3 Kafka架构图4 Kafka的应用场景 1 背景 场景&#xff1a; A服务每秒发送200个消息 B服务每秒处理100个消息 问题&#xff1a; B服务会被压垮&#xf…

微信小程序如何使用decimal计算金额

第三方库地址&#xff1a;GitHub - MikeMcl/decimal.js: An arbitrary-precision Decimal type for JavaScript 之前都是api接口走后端计算&#xff0c;偶尔发现这个库也不错&#xff0c;计算简单&#xff0c;目前发现比较准确 上代码 导入js import Decimal from ../../uti…

用 Python 给 Excel 表格截图(20250207)

我搜索了网络上的方案&#xff0c;感觉把 Excel 表格转换为 HTML 再用 platwright 截图是比较顺畅的路径&#xff0c;因为有顺畅的工具链。如果使用的是 Windows 系统则不需要阅读此文&#xff0c;因为 win32com 库更方便。这篇文章中 Excel 转 HTML 的方案&#xff0c;主要弥补…

8、Python 面试题解析:实例方法、静态方法和类方法的区别

Python 实例方法、静态方法和类方法详解 在 Python 中&#xff0c;实例方法、静态方法和类方法是三种不同类型的方法&#xff0c;它们的主要区别在于调用方式、参数传递和使用场景。以下从定义、语法、使用场景等方面全面解析&#xff0c;并附代码示例。 一、核心区别 方法类…

信创领域的PostgreSQL管理员认证

信创产业&#xff0c;全称为信息技术应用创新产业&#xff0c;是中国为应对国际技术竞争、保障信息安全、实现科技自立而重点发展的战略性新兴产业。其核心目标是通过自主研发和生态构建&#xff0c;逐步替代国外信息技术产品&#xff0c;形成自主可控的国产化信息技术体系。 发…