osclass增加支持webp格式

embedded/2025/2/8 15:23:48/

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/embedded/160566.html

相关文章

科技快讯 | 领英“隐私风波”告一段落;华为余承东智驾 1345 公里返工,称智界 R7 打赢“鸡蛋保卫战”;谷歌翻译将增“提问”功能

谷歌安卓 16 快捷设置被曝告别悬浮窗,选项在面板内展开 科技媒体Android Authority于1月30日发布博文,称谷歌安卓16更新中,快捷面板(Quick Setting)功能可能回归旧版样式。当前安卓版Quick Setting点击磁贴会扩展为浮动…

Mysql系列之--字符集

1、字符集 1.1、字符集简介 我们知道在计算机中只能存储二进制,那么如何将字符存储到计算机中,这个时候就需要将字符映射称为二进制,将所有字符映射为二进制就需要映射表。建立映射表需要注意: 1、明确哪些字符需要映射为二进制…

zzcms index.php存在SQL注入漏洞

免责声明: 本文旨在提供有关特定漏洞的深入信息,帮助用户充分了解潜在的安全风险。发布此信息的目的在于提升网络安全意识和推动技术进步,未经授权访问系统、网络或应用程序,可能会导致法律责任或严重后果。因此,作者不对读者基于本文内容所采取的任何行为承担责任。读者在…

python循环

while和for的区别 while 和 for 的区别,while是不定循环,循环次数不固定。for的循环次数通常是固定的 continue 跳出本次循环,直接执行下一次循环 break 退出循环,执行循环外的代码 exit() 退出python程序&#x…

DeepSeek与人工智能的结合:探索搜索技术的未来

云边有个稻草人-CSDN博客 目录 引言 一、DeepSeek的技术背景 1.1 传统搜索引擎的局限性 1.2 深度学习在搜索中的优势 二、DeepSeek与人工智能的结合 2.1 自然语言处理(NLP) 示例代码:基于BERT的语义搜索 2.2 多模态搜索 示例代码&…

【高级架构师】计算机网络基础:第二章 计算机网络体系结构(上)

文章目录 第二章 计算机网络体系结构2.1 常用的计算机网络体系结构2.1.1 OSI体系结构2.1.2 具有五层协议的体系结构 2.2 物理层2.2.1 物理层的基本概念2.2.2 传输媒体 2.3 数据链路层2.3.1 数据链路层概述2.3.2 封装成帧2.3.3 透明传输2.3.4 差错校验2.3.4 以太网2.3.5 以太网的…

Java面试评语及录用建议_面试录用评语.doc

面试录用评语 面试录用评语 面试评语 张三:语言表达简洁,富有条理,善于聆听,能从别人的观点中提炼总结出新的见解,但缺乏主动性和积极性, 李四:语言表达通顺,但不够简练&#xf…

深度学习 Pytorch 逻辑回归建模实验

接下来进行逻辑回归的建模实验,首先需要导入相关库和自定义的模块。 # 随机模块 import random# 绘图模块 import matplotlib as mpl import matplotlib.pyplot as plt# numpy import numpy as np# pytorch import torch from torch import nn,optim import torch.…