Serv00搭建 PixPro 若梦图床
PixPro:一款个人需求的高效图床,自带压缩并转换格式功能,有用好用且实用,接下来跟随我一起在servo00上搭建吧
注:也可在自己的服务器上搭建
保持耐心,有志竞成
项目地址
备份原文件(保存在R2)
安装
一点点小不足及补救
友情提示 使用Serv00搭建的好像不支持PNG格式上传 上传后会显示空白不显示图片
解决办法:复制以下代码 替换到 config/image_processing.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| <?php
function convertToWebp($source, $destination, $quality = 60) { $info = getimagesize($source);
if ($info['mime'] == 'image/jpeg') { $image = imagecreatefromjpeg($source); } elseif ($info['mime'] == 'image/gif') { return false; } else { return false; } $width = imagesx($image); $height = imagesy($image); $maxWidth = 2500; $maxHeight = 1600; if ($width > $maxWidth || $height > $maxHeight) { $ratio = min($maxWidth / $width, $maxHeight / $height); $newWidth = round($width * $ratio); $newHeight = round($height * $ratio); $newImage = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); imagedestroy($image); $image = $newImage; } $result = imagewebp($image, $destination, $quality); imagedestroy($image); gc_collect_cycles(); return $result; }
function convertPngWithImagick($source, $destination, $quality = 60) { try { $image = new Imagick($source);
if ($image->getImageAlphaChannel()) { $image->setImageBackgroundColor(new ImagickPixel('transparent')); $image->setImageAlphaChannel(Imagick::ALPHACHANNEL_ACTIVATE); $image = $image->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN); }
$image->setImageFormat('webp'); $image->setImageCompressionQuality($quality);
$width = $image->getImageWidth(); $height = $image->getImageHeight(); $maxWidth = 2500; $maxHeight = 1600;
if ($width > $maxWidth || $height > $maxHeight) { $ratio = min($maxWidth / $width, $maxHeight / $height); $newWidth = round($width * $ratio); $newHeight = round($height * $ratio); $image->resizeImage($newWidth, $newHeight, Imagick::FILTER_LANCZOS, 1); }
$result = $image->writeImage($destination); $image->clear(); $image->destroy(); return $result; } catch (Exception $e) { logMessage('Imagick转换PNG失败: ' . $e->getMessage()); return false; } }
function convertGifToWebp($source, $destination, $quality = 60) { try { $image = new Imagick(); $image->readImage($source); $image = $image->coalesceImages(); foreach ($image as $frame) { $frame->setImageFormat('webp'); $frame->setImageCompressionQuality($quality); } $image = $image->optimizeImageLayers(); $result = $image->writeImages($destination, true); $image->clear(); $image->destroy(); return $result; } catch (Exception $e) { logMessage('GIF转换WebP失败: ' . $e->getMessage()); return false; } }
function processImageCompression($fileMimeType, $newFilePath, $newFilePathWithoutExt, $quality) { $convertSuccess = true; $finalFilePath = $newFilePath;
if ($fileMimeType === 'image/png') { $convertSuccess = convertPngWithImagick($newFilePath, $newFilePathWithoutExt . '.webp', $quality); if ($convertSuccess) { $finalFilePath = $newFilePathWithoutExt . '.webp'; unlink($newFilePath); } } elseif ($fileMimeType === 'image/gif') { $convertSuccess = convertGifToWebp($newFilePath, $newFilePathWithoutExt . '.webp', $quality); if ($convertSuccess) { $finalFilePath = $newFilePathWithoutExt . '.webp'; unlink($newFilePath); } } elseif ($fileMimeType !== 'image/webp' && $fileMimeType !== 'image/svg+xml') { $convertSuccess = convertToWebp($newFilePath, $newFilePathWithoutExt . '.webp', $quality); if ($convertSuccess) { $finalFilePath = $newFilePathWithoutExt . '.webp'; unlink($newFilePath); } }
return [$convertSuccess, $finalFilePath]; } ?>
|
- 注册好serv00后进入
WWW websites面板添加自己的域名(也可以使用serv00提供的域名,但是在国内被墙了)

- 进入
DNS zones面板将你所添加域名的A记录添加至你的域名解析商(这里我使用的是Cloudflare)



- 创建数据库,这里我们可以使用serv00提供的MySQl数据库。进入
MySQL面板并创建数据库,在这里请牢记数据库名字以及密码

- 进入
File manager面板,进入domains文件夹下域名所对应的文件夹


- 进入域名对应的
public_html文件夹,删除已存在的index.html文件

- 将下载的源码解压至域名对应的
public_html文件夹


- 全选解压后的文件,复制粘贴至
public_html文件夹


- 修改PHP版本 :在域名目录下创建一个文本,名为:.htaccess


关键一步:选择Text Editor添加以下代码并保存
1
| AddType application/x-httpd-php81 .php
|

- 进入浏览器,打开域名进入网站安装页面,填入主机名、数据库名和密码,并设置自己的管理页面和密码

本地安装如下图所示:
注意!!!:若需要接入Cloudflare R2,则这里一定要选择S3方式,R2相关的配置参数在下文,如需可在目录直达

- (可选)代理缓存加速访问:进入
File manager面板找到域名文件夹里的config.ini文件,下载并修改protocol值为可代理缓存的域名并重新上传保存即可

演示站点
管理页面:
账号:helloworld
密码:helloworld
配置R2
创建R2储存桶
进入 Cloudflare R2 ,点击“创建”以创建一个R2储存桶,名字随便起即可,位置选择亚太地区后点击创建存储桶


配置Cloudflare R2储存桶
创建之后进入第三个菜单设置,找到到 R2.dev 子域,设置为允许访问 ,并复制公共 R2.dev 存储桶 URL,保存以备用


其他参数准备
S3 Endpoint
注意:保存url即可,无需存储桶名称

- S3 Access Key ID和S3 Access Key Secret
点击右上角按钮创建 API token,进入创建 API Token 页面

然后创建对应 API token,鉴于需要读写 S3 存储服务,因此权限需要选择对象读与写,然后点击创建。

创建完成后,就可以看到对应的 S3 API token,复制对应的变量并保存以备用
接入PixPro图床
进入图床配置界面,配置所需参数如下表所示:
| 参数 | 值 |
|---|
| S3 Region | auto |
| S3 Bucket | 存储桶名称 |
| S3 Endpoint | S3API |
| S3 Access Key ID | R2API令牌访问密钥 |
| S3 Access Key Secret | R2API令牌机密访问密钥 |
| S3 自定义域名 | https//:···R2.dev 添加的自定义域 或 R2 分配的域名(此处也可直接添加代理缓存以加速访问,不需要忽视此备注即可) |
然后点击完成安装即可,这时图片均保存在R2储存桶中,上传的图片可在R2中找到
保活(附加内容)
申请端口
进入Port reservation面板,选择 Add port标签栏, Random随机即可,然后点击 Add;选择 Port list 标签栏,记下你分配到的TCP端口号


开启管理执行权限
进入Run your own applications,点击Enabled ; 使其Status变为✅Enabled即可

执行一键脚本
- 首先进入WebSSH,填入
Hostname / 主机(这里如果“s13.serv00.com”连接失败就填入“web13.serv00.com”) Username / 用户名 Password / 密码,点击Connect / 连接

- 然后输入如下脚本回车
1
| bash <(curl -s https://raw.githubusercontent.com/cmliu/socks5-for-serv00/main/install-socks5.sh)
|
注意:在输入socks5端口号时,输入申请端口时记录的TCP端口号即可,其余参数可以自行输入任意内容;

- 配置完成脚本后推荐添加 crontab 守护进程的计划任务,输入
y后回车即可,等待完成后即可查看crontab任务是否添加成功

Fork cmliu/socks5-for-serv00
添加 在Secrets and variables中选择Actions添加ACCOUNTS_JSON 变量,格式如下:
1 2 3 4 5 6
| [ {"username": "lianli111", "password": "OpPZm8······NWjc", "panel": "panel12.serv00.com", "ssh": "s12.serv00.com"}, {"username": "lianli222", "password": "yXM······I5", "panel": "panel12.serv00.com", "ssh": "s12.serv00.com"}, {"username": "lianli333", "password": "M&WA······d&AnpB", "panel": "panel13.serv00.com", "ssh": "s13.serv00.com"}, {"username": "opplzz", "password": "WnFX······z28T", "panel": "panel13.serv00.com", "ssh": "s13.serv00.com"} ]
|

- 开启Actions保活
