n/programu/jinkesi · 2024-10-22
注册 登录
n/program · 2024-10-22 · 已编辑 · 424 次浏览
u/jinkesi白银

Serv00上搭建一个PixPro图床,内存太小,我们可以接入到CFR2 足够个人使用。自己有VPS的也可在宝塔上面部署

### 面板页

png~~

### 后台页

png~~

~~~~友情提示 使用Serv00搭建的好像不支持PNG格式上传 上传后会显示空白不显示图片

### Serv00图床 ~~</s>PNG上传空白<e> 解决办法 复制以下代码 替换到 </s>config/image_processing.php<e>

&lt;?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 &gt; $maxWidth || $height &gt; $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-&gt;getImageAlphaChannel()) {
            // 设置背景颜色为透明
            $image-&gt;setImageBackgroundColor(new ImagickPixel('transparent'));
            $image-&gt;setImageAlphaChannel(Imagick::ALPHACHANNEL_ACTIVATE);
            $image = $image-&gt;mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
        }

        $image-&gt;setImageFormat('webp');
        $image-&gt;setImageCompressionQuality($quality);

        $width = $image-&gt;getImageWidth();
        $height = $image-&gt;getImageHeight();
        $maxWidth = 2500;
        $maxHeight = 1600;

        if ($width &gt; $maxWidth || $height &gt; $maxHeight) {
            $ratio = min($maxWidth / $width, $maxHeight / $height);
            $newWidth = round($width * $ratio);
            $newHeight = round($height * $ratio);
            $image-&gt;resizeImage($newWidth, $newHeight, Imagick::FILTER_LANCZOS, 1);
        }

        $result = $image-&gt;writeImage($destination);
        $image-&gt;clear();
        $image-&gt;destroy();
        return $result;
    } catch (Exception $e) {
        logMessage('Imagick转换PNG失败: ' . $e-&gt;getMessage());
        return false;
    }
}

/**
 * 使用Imagick将GIF图片转换为WebP格式
 */
function convertGifToWebp($source, $destination, $quality = 60) {
    try {
        $image = new Imagick();
        $image-&gt;readImage($source);
        $image = $image-&gt;coalesceImages();
        foreach ($image as $frame) {
            $frame-&gt;setImageFormat('webp');
            $frame-&gt;setImageCompressionQuality($quality);
        }
        $image = $image-&gt;optimizeImageLayers();
        $result = $image-&gt;writeImages($destination, true);
        $image-&gt;clear();
        $image-&gt;destroy();
        return $result;
    } catch (Exception $e) {
        logMessage('GIF转换WebP失败: ' . $e-&gt;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' &amp;&amp; $fileMimeType !== 'image/svg+xml') {
        $convertSuccess = convertToWebp($newFilePath, $newFilePathWithoutExt . '.webp', $quality);
        if ($convertSuccess) {
            $finalFilePath = $newFilePathWithoutExt . '.webp';
            unlink($newFilePath);
        }
    }

    return [$convertSuccess, $finalFilePath];
}
?&gt;
<e>```</e>

~~###~~ 也可下载 <URL url="https://pixpinapp.com/">~~[~~PixPin<e>](https://pixpinapp.com/)</e></URL>  截图软件试试<e> </e>


~~###~~ 安装前准备


**~~**~~<URL url="https://www.serv00.com/">~~[~~Serv00账号注册<e>](https://www.serv00.com/)</e></URL><e>**</e>**


<URL url="https://github.com/JLinMr/PixPro/">~~[~~PixPro项目地址<e>](https://github.com/JLinMr/PixPro/)</e></URL>


~~##~~ 安装步骤


<LIST type="decimal">
- ~~1.~~ 注册好Serv00账号打开网页进入到面板端添加域名或者用自己的域名都行,这里我用别的网站注册的二级域名。如下图添加
![img](https://assets.vviptuangou.com/65b5e8853269dc1517f0c29312f405ec4ff93aac.jpg)~~![~~img<e>](https://assets.vviptuangou.com/65b5e8853269dc1517f0c29312f405ec4ff93aac.jpg)</e>



- ~~2.~~ 把里面的A记录解析你托管到CF的域名或者别的地方申请的
![img](https://assets.vviptuangou.com/89fad1033d1bc063cc48549c59ccc86f90fc45b7.jpg)~~![~~img<e>](https://assets.vviptuangou.com/89fad1033d1bc063cc48549c59ccc86f90fc45b7.jpg)</e>
![png](https://assets.vviptuangou.com/42cb9cc5ef879bd3ff44afae6058f2b589f3ad04.jpg)~~![~~png<e>](https://assets.vviptuangou.com/42cb9cc5ef879bd3ff44afae6058f2b589f3ad04.jpg)</e>



- ~~3.~~ 按照下图打开域名的权限
![png](https://assets.vviptuangou.com/65f930477953843e868fa55a5b9303716e659ed3.jpg)~~![~~png<e>](https://assets.vviptuangou.com/65f930477953843e868fa55a5b9303716e659ed3.jpg)</e>
![png](https://assets.vviptuangou.com/6bead65cbca8e9bf5284e0bd0809cbccd524fbd6.jpg)~~![~~png<e>](https://assets.vviptuangou.com/6bead65cbca8e9bf5284e0bd0809cbccd524fbd6.jpg)</e>
点击Save等待成功



- ~~4.~~ 创建MySQL数据库(保存账号及地址)
![png](https://assets.vviptuangou.com/495fafb3a994859395fceac7d6af587ecae551a9.jpg)~~![~~png<e>](https://assets.vviptuangou.com/495fafb3a994859395fceac7d6af587ecae551a9.jpg)</e>
![png](https://assets.vviptuangou.com/6e54144c39f77ee9fdfa22683ebcd946f136993e.jpg)~~![~~png<e>](https://assets.vviptuangou.com/6e54144c39f77ee9fdfa22683ebcd946f136993e.jpg)</e>



- ~~5.~~ <URL url="https://github.com/JLinMr/PixPro/releases/tag/v1.7.6">~~[~~下载ZIP文件<e>](https://github.com/JLinMr/PixPro/releases/tag/v1.7.6)</e></URL>



- ~~6.~~ 上传安装包并解压进入文件管理器
![image](/uploads/original/89/892b0f0c993b2c815ac2b82bd67a589d2c0a0b9e.png)~~![~~image<e>](/uploads/original/89/892b0f0c993b2c815ac2b82bd67a589d2c0a0b9e.png)</e>



- ~~7.~~ 进入public_html文件夹删除其下所有文件
![image](/uploads/original/89/892b0f0c993b2c815ac2b82bd67a589d2c0a0b9e.png)~~![~~image<e>](/uploads/original/89/892b0f0c993b2c815ac2b82bd67a589d2c0a0b9e.png)</e>



- ~~8.~~ 上传安装包到你添加的域名或者Serv00自带域名下
![undefined](https://assets.vviptuangou.com/b7301c6bb01e09fa8212834c3e6af4b68ac3bab7.jpg)~~![~~undefined<e>](https://assets.vviptuangou.com/b7301c6bb01e09fa8212834c3e6af4b68ac3bab7.jpg)</e>
![undefined](https://assets.vviptuangou.com/0a35e541298e16d5b424e37711df220196fcb608.jpg)~~![~~undefined<e>](https://assets.vviptuangou.com/0a35e541298e16d5b424e37711df220196fcb608.jpg)</e>



- ~~9.~~ 选择你们下载文件的路径上传好如下图
![undefined](https://assets.vviptuangou.com/475b0cc5380aa5c6a098a587c96d960f2bea8bb6.jpg)~~![~~undefined<e>](https://assets.vviptuangou.com/475b0cc5380aa5c6a098a587c96d960f2bea8bb6.jpg)</e>
![undefined](https://assets.vviptuangou.com/7bbf3b21347003fd80c632298441fad9fdecb043.jpg)~~![~~undefined<e>](https://assets.vviptuangou.com/7bbf3b21347003fd80c632298441fad9fdecb043.jpg)</e>
![undefined](https://assets.vviptuangou.com/d8ab33579a8b00b259be673f18c53cfcd373bb71.jpg)~~![~~undefined<e>](https://assets.vviptuangou.com/d8ab33579a8b00b259be673f18c53cfcd373bb71.jpg)</e>
</LIST>

~~###~~ 和上一步一样


<LIST start="10" type="decimal">
- ~~10.~~ 进去后如下图所以我们<C>~~`</s>Shift<e>`</e></C>建一直按着然后点击鼠标左键全选
![undefined](https://assets.vviptuangou.com/fffb74f2162d5d0bc0c382ceea298fb9c0fcc8eb.jpg)![~~undefined<e>](https://assets.vviptuangou.com/fffb74f2162d5d0bc0c382ceea298fb9c0fcc8eb.jpg)</e>



- ~~11.~~ 移动到我们开始创建域名目录下的<C>~~`</s>public_html<e>`</e></C>
![png](https://assets.vviptuangou.com/048b5580f71361a883e023b5016b137ac4ab5bdd.jpg)![~~png<e>](https://assets.vviptuangou.com/048b5580f71361a883e023b5016b137ac4ab5bdd.jpg)</e>



- ~~12.~~ 修改PHP版本 在域名目录下创建一个文本,名为:<C>~~`</s>.htaccess<e>`</e></C>  
![png](https://assets.vviptuangou.com/fa3c6470d9afea1785903b6c93046186052fb2e8.jpg)![~~png<e>](https://assets.vviptuangou.com/fa3c6470d9afea1785903b6c93046186052fb2e8.jpg)</e>
![png](https://assets.vviptuangou.com/167e762e94fa1e2ddd4bd29064e573a59934a377.jpg)~~![~~png<e>](https://assets.vviptuangou.com/167e762e94fa1e2ddd4bd29064e573a59934a377.jpg)</e>



- ~~13.~~ 添加PHP版本
![E.png](https://assets.vviptuangou.com/b6f389d7bbf07970ae10d26445b1ec5017906da9.jpg)~~![~~E.png<e>](https://assets.vviptuangou.com/b6f389d7bbf07970ae10d26445b1ec5017906da9.jpg)</e>
</LIST>

**~~**~~选择<C>~~`</s>Text Editor<e>`</e></C> 添加以下代码<e>**</e>**


AddType application/x-httpd-php81 .php
![png](https://assets.vviptuangou.com/8846fa57b96c746e82c98c3cff83192c333978e0.jpg)![~~png<e>](https://assets.vviptuangou.com/8846fa57b96c746e82c98c3cff83192c333978e0.jpg)</e>


<LIST start="14" type="decimal">
- ~~14.~~ 访问你的域名开始安装系统,管理员账户和密码自己设置 ,如果要接入<C>~~`</s>CFR2<e>`</e></C>我们存储选择 <C>`</s>S3<e>`</e></C> 下面我会写<C>`</s>S3<e>`</e></C>安装方式
![png](https://assets.vviptuangou.com/88ae10370b1c2c2a1e9c2980228371982944f72b.jpg)![~~png<e>](https://assets.vviptuangou.com/88ae10370b1c2c2a1e9c2980228371982944f72b.jpg)</e>
![png](https://assets.vviptuangou.com/a3bf9c47a9b8cd6590165729e0c3c79f1169ac9b.jpg)~~![~~png<e>](https://assets.vviptuangou.com/a3bf9c47a9b8cd6590165729e0c3c79f1169ac9b.jpg)</e>
![png](https://assets.vviptuangou.com/41eba336ae11799d9f93b9e2ea430626be4a8705.jpg)~~![~~png<e>](https://assets.vviptuangou.com/41eba336ae11799d9f93b9e2ea430626be4a8705.jpg)</e>



- ~~15.~~ 点击回到首页就可以上传图片了
![png](https://assets.vviptuangou.com/1b0c08bb32bc384db6982aac4ed6f58ac464fd92.jpg)~~![~~png<e>](https://assets.vviptuangou.com/1b0c08bb32bc384db6982aac4ed6f58ac464fd92.jpg)</e>
</LIST>

<FP char="—">---</FP>

~~###~~ 接入R2 前提 已开通 Cloudflare R2


~~###~~ 进入到 Cloudflare 面板 找到 R2 右边有一个管理 R2API 令牌点击创建 API令牌 ,创建好后里面有我们需要的访问密钥和机密访问密钥


![3K](https://assets.vviptuangou.com/127c616330870251adb6897b04d0ca0e8ba830b0.jpg)~~![~~3K<e>](https://assets.vviptuangou.com/127c616330870251adb6897b04d0ca0e8ba830b0.jpg)</e>


~~###~~ 1. 进入到 Cloudflare 面板 找到 R2 点击创建存储桶


![1](https://assets.vviptuangou.com/eee36ef2f9e5086de6d3dbb93e8b28ff4fe26577.jpg)~~![~~1<e>](https://assets.vviptuangou.com/eee36ef2f9e5086de6d3dbb93e8b28ff4fe26577.jpg)</e>



~~###~~ 2. 进入后名称随便写。位置选择亚太地区后点击创建存储桶


![2](https://assets.vviptuangou.com/2de4727294de8dde45ea7c6b773cbc1628d70abe.jpg)~~![~~2<e>](https://assets.vviptuangou.com/2de4727294de8dde45ea7c6b773cbc1628d70abe.jpg)</e>


~~###~~ 3. 创建好后点击设置拉到下面看到 R2.dev 子域点击后面的允许访问 , 连接域需要添加你托管到CF上面域名


![3](https://assets.vviptuangou.com/99e549d954615e6279ee8295e75d63e920075cf8.jpg)~~![~~3<e>](https://assets.vviptuangou.com/99e549d954615e6279ee8295e75d63e920075cf8.jpg)</e>


~~###~~ 4. 14 步我们安装选择<C>~~`</s>S3<e>`</e></C>后看到下图<e> </e>


![4](https://assets.vviptuangou.com/89d9aa12a4d7de30f6ce84acd5d395b920d3e4e0.jpg)![~~4<e>](https://assets.vviptuangou.com/89d9aa12a4d7de30f6ce84acd5d395b920d3e4e0.jpg)</e>


*|* 参数  *|* 值  *|*

*| --- | --- |*
*|* S3 Region  *|* auto  *|*

*|* S3 Bucket  *|* 你的存储桶名称  *|*

*|* S3 Endpoint  *|* 你的S3API 后面不要加你的存储桶名称  *|*

*|* S3 Access Key ID  *|* R2API令牌访问密钥  *|*

*|* S3 Access Key Secret  *|* R2API令牌机密访问密钥  *|*

*|* S3 自定义域名  *|* R2.dev 添加的自定义域 或 R2 分配的域名  *|*



~~###~~ 5. 点击完成安装即可。这是我们上传好的图片 我下面的域名就是我们 R2 分配的域名<e> </e>


![5](https://assets.vviptuangou.com/debdfa2a267ad44bde508936288285b528bd781b.jpg)~~![~~5<e>](https://assets.vviptuangou.com/debdfa2a267ad44bde508936288285b528bd781b.jpg)</e>


~~###~~ 6. 我们回到 Cloudflare R2 就会看到刚刚上传的图片


![6](https://assets.vviptuangou.com/8f23c10386b3907fc6a5e03a026af498e6fd9767.jpg)~~![~~6<e>](https://assets.vviptuangou.com/8f23c10386b3907fc6a5e03a026af498e6fd9767.jpg)</e>
</r>
0
6
登录后参与讨论。
u/udc2b6nr 广告
QuicksilverVPN

快银 VPN,一键连接全球节点,线路稳定、延迟低。支持 Windows、macOS 等多平台,TUN 全局模式覆盖全部应用流量。无需复杂配置,下载即用。

umami.dnsl.top 了解更多

6 条回复

排序
  1. jinkesi 白银 楼主 2024-10-22

    [[21],[2]]

    0
  2. mili 荣誉会员 王者 圣贤 2024-10-22

    感谢辛苦整理

    0
  3. jinkesi 白银 楼主 2024-10-22

    @"米粒"#p123611 感谢大佬莅临:huaji02:

    0
  4. heiyu 🌩 钻石 2 YEARS 2024-10-22

    不错的教程

    0
  5. joylucky 白银 2024-10-23

    感谢大佬分享:ac32:

    0
  6. zxypp 白银 2024-10-23

    [[2],[2,40]]

    0