title: 【白嫖】使用 CloudFlare R2 搭建个人图床 urlname: -bai-piao--shi-yong-CloudFlare-R2-da-jian-ge-ren-tu-chuang date: 2023-08-27 20:32:03 index_img: https://api.limour.top/randomImg?d=2023-08-27 20:32:03 tags: ['docker', 'ngpm', 'r2']
Free | Paid - Rates | |
---|---|---|
存储 | 10 GB / month | $0.015 / GB-month |
A 类操作 | 1 million requests / month | $4.50 / million requests |
B 类操作 | 10 million requests / month | $0.36 / million requests |
mkdir -p ~/app/Lsky && cd ~/app/Lsky && nano docker-compose.yml
docker-compose up -d
version: '3.3'
services:
lsky-pro:
restart: always
volumes:
- './lsky-pro-data:/var/www/html'
image: 'dko0/lsky-pro'
networks:
default:
external: true
name: ngpm
sudo -v ; curl https://rclone.org/install.sh | sudo bash -s beta
nano ~/.config/rclone/rclone.conf
[img]
type = s3
provider = Cloudflare
access_key_id = xxx
secret_access_key = xxxxxx
endpoint = https://<accountid>.r2.cloudflarestorage.com
acl = private
rclone lsd img:limour-img
git clone https://oauth2:ghp_xxx@github.com/limour-blog/img-bed.git
rclone copy --ignore-existing --progress --ignore-errors img:limour-img ~/img-bed
cd ~/img-bed
git add . && git commit -m 'backup' && git push -u origin main
D:\ImageMagick-7.1.1-Q16\magick.exe convert -resize 512x512^ -gravity North -extent 512x512 -quality 50 -define WebP:lossless=false F:\temp\randImg\*.jpg 26.webp
# 顶部 -gravity North
# 底部 -gravity South
# 中间 -gravity center
# 右侧 -gravity East
# 左侧 -gravity West
mkdir ~/img-bed
apt install imagemagick
convert -version
# 6.9.11
# 将 ~/app/Lsky/lsky-pro-data/storage/app/uploads 目录及其所有的子目录的 png 后缀的图片转换成 webp
# 在保持目录结构不变的前提下,保存到 ~/img-bed 目录下
# 非 png 的文件则直接复制
find ~/app/Lsky/lsky-pro-data/storage/app/uploads -type f -name "*.png" -exec sh -c 'mkdir -p ~/img-bed/$(dirname {}); convert {} -quality 30 -define webp:lossless=false ~/img-bed/$(dirname {})/$(basename {} .png).webp' \;
find ~/app/Lsky/lsky-pro-data/storage/app/uploads -type f ! -name "*.png" -exec sh -c 'mkdir -p ~/img-bed/$(dirname {}); cp {} ~/img-bed/$(dirname {})/$(basename {})' \;
mv ~/img-bed/root/app/Lsky/lsky-pro-data/storage/app/* ~/img-bed & rm -rf ~/img-bed/root & mv ~/img-bed/uploads ~/img-bed/archives_2023
rclone lsd img:limour-img
rclone copy --ignore-existing --progress --ignore-errors ~/img-bed img:limour-img
修改原文章图片地址 _posts
目录
sed -i 's|https://img-cdn.limour.top/i/|https://img.limour.top/archives_2023/|g' *.md
sed -i 's|https://img-cdn.limour.top/|https://img.limour.top/archives_2023/|g' *.md
sed -i 's#https://img.limour.top/archives_2023/\(.*\)\.png#https://img.limour.top/archives_2023/\1.webp#g' *.md