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

### 面板页

png![png](https://assets.vviptuangou.com/a7851a9a4cb48ce3008bdf5b6835f6f2b2446aba.jpg)

### 后台页

png![png](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-&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->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];
    }
    ?>
    ```

### 也可下载 [PixPin](https://pixpinapp.com/) 截图软件试试

### 安装前准备

**[Serv00账号注册](https://www.serv00.com/)**

[PixPro项目地址](https://github.com/JLinMr/PixPro/)

## 安装步骤

  • 1.

    注册好Serv00账号打开网页进入到面板端添加域名或者用自己的域名都行,这里我用别的网站注册的二级域名。如下图添加

    img</s>img<e>

  • 2.

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

  • 3.

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

  • 4.

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

  • 5.

    [下载ZIP文件](https://github.com/JLinMr/PixPro/releases/tag/v1.7.6)

  • 6.

    上传安装包并解压进入文件管理器
    image![image](https://i.111666.best/image/lwU3tB1yOBMU3BGgCgbYEP.png)

  • 7.

    进入public_html文件夹删除其下所有文件
    image![image](https://i.111666.best/image/rW0Dia44iDyGLjkFJf65zT.png)

  • 8.

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

  • 9.

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

  • ### 和上一步一样

  • 10.

    进去后如下图所以我们</s>Shift<e>建一直按着然后点击鼠标左键全选

    undefined</s>undefined<e>

  • 11.

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

  • 12.

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

  • 13.

    添加PHP版本
    E.png![E.png](https://assets.vviptuangou.com/b6f389d7bbf07970ae10d26445b1ec5017906da9.jpg)

  • **选择`Text Editor` 添加以下代码**

    </s><i> </i>AddType application/x-httpd-php81 .php<i> </i><e>

    png![png](https://assets.vviptuangou.com/8846fa57b96c746e82c98c3cff83192c333978e0.jpg)

  • 14.

    访问你的域名开始安装系统,管理员账户和密码自己设置 ,如果要接入</s>CFR2<e>我们存储选择 </s>S3<e> 下面我会写</s>S3<e>安装方式

    png</s>png<e>

    png</s>png<e>

    png</s>png<e>

  • 15.

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

  • ---

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

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

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

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

    1![1](https://assets.vviptuangou.com/eee36ef2f9e5086de6d3dbb93e8b28ff4fe26577.jpg)


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

    2![2](https://assets.vviptuangou.com/2de4727294de8dde45ea7c6b773cbc1628d70abe.jpg)

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

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

    ### 4. 14 步我们安装选择`S3`后看到下图

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

    | | | | --- | --- || | || | || | || | || | || | |
    参数
    S3 Regionauto
    S3 Bucket你的存储桶名称
    S3 Endpoint你的S3API 后面不要加你的存储桶名称
    S3 Access Key IDR2API令牌访问密钥
    S3 Access Key SecretR2API令牌机密访问密钥
    S3 自定义域名R2.dev 添加的自定义域 或 R2 分配的域名

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

    5![5](https://assets.vviptuangou.com/debdfa2a267ad44bde508936288285b528bd781b.jpg)

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

    6![6](https://assets.vviptuangou.com/8f23c10386b3907fc6a5e03a026af498e6fd9767.jpg)

    [[21],[2]]

    感谢辛苦整理


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

    不错的教程

    感谢大佬分享:ac32:

    [[2],[2,40]]