Serv00上搭建一个 PixPro 若梦图床 + 接入Cloudflare R2
本帖最后由 jinx2024 于 2024-11-14 13:02 编辑##Serv00上搭建一个PixPro图床,内存太小,我们可以接入到CFR2 足够个人使用。自己有VPS的也可在宝塔上面部署
---
### 面板页
!(https://assets.vviptuangou.com/a7851a9a4cb48ce3008bdf5b6835f6f2b2446aba.jpg)
### 后台页
!(https://assets.vviptuangou.com/81b3a97608fce33725b887f5888863903a6b70de.jpg)
**友情提示 使用Serv00搭建的好像不支持PNG格式上传 上传后会显示空白不显示图片**
### Serv00图床 `PNG上传空白` 解决办法复制以下代码 替换到 `config/image_processing.php`
``` PHP
<?php
/**
* 将JPEG图片转换为WebP格式
*/
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;
}
/**
* 使用Imagick将PNG图片转换为WebP格式
*/
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;
}
}
/**
* 使用Imagick将GIF图片转换为WebP格式
*/
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];
}
?>
```
### 也可下载 (https://pixpinapp.com/)截图软件试试
### 安装前准备
**(https://www.serv00.com/)**
> (https://github.com/JLinMr/PixPro/)
## 安装步骤
1. 注册好Serv00账号打开网页进入到面板端添加域名或者用自己的域名都行,这里我用别的网站注册的二级域名。如下图添加
!(https://assets.vviptuangou.com/65b5e8853269dc1517f0c29312f405ec4ff93aac.jpg)
2. 把里面的A记录解析你托管到CF的域名或者别的地方申请的
!(https://assets.vviptuangou.com/89fad1033d1bc063cc48549c59ccc86f90fc45b7.jpg)
!(https://assets.vviptuangou.com/42cb9cc5ef879bd3ff44afae6058f2b589f3ad04.jpg)
3. 按照下图打开域名的权限
!(https://assets.vviptuangou.com/65f930477953843e868fa55a5b9303716e659ed3.jpg)
!(https://assets.vviptuangou.com/6bead65cbca8e9bf5284e0bd0809cbccd524fbd6.jpg)
点击Save等待成功
4. 创建MySQL数据库(保存账号及地址)
!(https://assets.vviptuangou.com/495fafb3a994859395fceac7d6af587ecae551a9.jpg)
!(https://assets.vviptuangou.com/6e54144c39f77ee9fdfa22683ebcd946f136993e.jpg)
5.[下载ZIP文件](https://github.com/JLinMr/PixPro/releases/tag/v1.7.6)
6. 上传安装包并解压进入文件管理器
!(https://i.111666.best/image/lwU3tB1yOBMU3BGgCgbYEP.png)
7. 进入public_html文件夹删除其下所有文件
!(https://i.111666.best/image/rW0Dia44iDyGLjkFJf65zT.png)
8. 上传安装包到你添加的域名或者Serv00自带域名下
!(https://assets.vviptuangou.com/b7301c6bb01e09fa8212834c3e6af4b68ac3bab7.jpg)
!(https://assets.vviptuangou.com/0a35e541298e16d5b424e37711df220196fcb608.jpg)
9. 选择你们下载文件的路径上传好如下图
!(https://assets.vviptuangou.com/475b0cc5380aa5c6a098a587c96d960f2bea8bb6.jpg)
!(https://assets.vviptuangou.com/7bbf3b21347003fd80c632298441fad9fdecb043.jpg)
!(https://assets.vviptuangou.com/d8ab33579a8b00b259be673f18c53cfcd373bb71.jpg)
### 和上一步一样
10. 进去后如下图所以我们`Shift`建一直按着然后点击鼠标左键全选
!(https://assets.vviptuangou.com/fffb74f2162d5d0bc0c382ceea298fb9c0fcc8eb.jpg)
11. 移动到我们开始创建域名目录下的`public_html`
!(https://assets.vviptuangou.com/048b5580f71361a883e023b5016b137ac4ab5bdd.jpg)
12. 修改PHP版本 在域名目录下创建一个文本,名为:`.htaccess`
!(https://assets.vviptuangou.com/fa3c6470d9afea1785903b6c93046186052fb2e8.jpg)
!(https://assets.vviptuangou.com/167e762e94fa1e2ddd4bd29064e573a59934a377.jpg)
13. 添加PHP版本
!(https://assets.vviptuangou.com/b6f389d7bbf07970ae10d26445b1ec5017906da9.jpg)
**选择`Text Editor` 添加以下代码**
```
AddType application/x-httpd-php81 .php
```
!(https://assets.vviptuangou.com/8846fa57b96c746e82c98c3cff83192c333978e0.jpg)
14. 访问你的域名开始安装系统,管理员账户和密码自己设置 ,如果要接入`CFR2`我们存储选择 `S3` 下面我会写`S3`安装方式
!(https://assets.vviptuangou.com/88ae10370b1c2c2a1e9c2980228371982944f72b.jpg)
!(https://assets.vviptuangou.com/a3bf9c47a9b8cd6590165729e0c3c79f1169ac9b.jpg)
!(https://assets.vviptuangou.com/41eba336ae11799d9f93b9e2ea430626be4a8705.jpg)
15. 点击回到首页就可以上传图片了
!(https://assets.vviptuangou.com/1b0c08bb32bc384db6982aac4ed6f58ac464fd92.jpg)
---
### 接入R2 前提 已开通 Cloudflare R2
### 进入到 Cloudflare 面板 找到 R2 右边有一个管理 R2API 令牌点击创建 API令牌 ,创建好后里面有我们需要的访问密钥和机密访问密钥
!(https://assets.vviptuangou.com/127c616330870251adb6897b04d0ca0e8ba830b0.jpg)
### 1. 进入到 Cloudflare 面板 找到 R2 点击创建存储桶
!(https://assets.vviptuangou.com/eee36ef2f9e5086de6d3dbb93e8b28ff4fe26577.jpg)
### 2. 进入后名称随便写。位置选择亚太地区后点击创建存储桶
!(https://assets.vviptuangou.com/2de4727294de8dde45ea7c6b773cbc1628d70abe.jpg)
### 3. 创建好后点击设置拉到下面看到 R2.dev 子域点击后面的允许访问 , 连接域需要添加你托管到CF上面域名
!(https://assets.vviptuangou.com/99e549d954615e6279ee8295e75d63e920075cf8.jpg)
### 4. 14 步我们安装选择`S3`后看到下图
!(https://assets.vviptuangou.com/89d9aa12a4d7de30f6ce84acd5d395b920d3e4e0.jpg)
| 参数 | 值 |
| --- | --- |
| S3 Region | auto |
| S3 Bucket | 你的存储桶名称 |
| S3 Endpoint | 你的S3API 后面不要加你的存储桶名称 |
| S3 Access Key ID | R2API令牌访问密钥 |
| S3 Access Key Secret | R2API令牌机密访问密钥 |
| S3 自定义域名 | R2.dev 添加的自定义域 或 R2 分配的域名 |
### 5. 点击完成安装即可。这是我们上传好的图片 我下面的域名就是我们 R2 分配的域名
!(https://assets.vviptuangou.com/debdfa2a267ad44bde508936288285b528bd781b.jpg)
### 6. 我们回到 Cloudflare R2 就会看到刚刚上传的图片
!(https://assets.vviptuangou.com/8f23c10386b3907fc6a5e03a026af498e6fd9767.jpg)
页:
[1]