国外有哪些CDN或者云存储支持图片处理 Nodejs
国外有哪些CDN或者云存储支持图片处理 Nodejs
就像阿里云或者又拍云那样 更根据URL参数进行图片缩放、裁剪
阿里云的不错 但是要备案 太麻烦
5 回复
国外有哪些CDN或者云存储支持图片处理 Node.js
在国外寻找支持图片处理的CDN或云存储服务时,你可以考虑使用像Cloudinary和Imgix这样的平台。这些平台不仅提供了强大的图片处理功能,还支持通过URL参数动态调整图片大小、裁剪、格式转换等操作。
Cloudinary
Cloudinary是一个非常流行的图片管理平台,它支持多种语言和框架,包括Node.js。以下是一个简单的示例,展示如何使用Cloudinary在Node.js中处理图片:
-
安装Cloudinary库:
npm install cloudinary
-
初始化Cloudinary: 在你的项目中设置Cloudinary配置。你需要在Cloudinary网站上注册并获取API密钥。
const cloudinary = require('cloudinary').v2; cloudinary.config({ cloud_name: 'YOUR_CLOUD_NAME', api_key: 'YOUR_API_KEY', api_secret: 'YOUR_API_SECRET' });
-
上传图片并生成处理后的URL:
// 上传图片到Cloudinary cloudinary.uploader.upload("path/to/your/image.jpg", { public_id: "my_image" }, function(error, result) { console.log(result); }); // 生成处理后的URL const url = cloudinary.url("my_image", { width: 100, height: 150, crop: "fill" }); console.log(url); // 输出类似 https://res.cloudinary.com/YOUR_CLOUD_NAME/image/upload/w_100,h_150,c_fill/my_image.jpg 的URL
Imgix
Imgix也是一个强大的图片处理服务,支持多种CDN和云存储,如AWS S3、Google Cloud Storage等。以下是如何使用Imgix的简单示例:
-
安装Imgix库:
npm install imgix-core-js
-
初始化Imgix客户端:
const { ImgixClient } = require('imgix-core-js'); const client = new ImgixClient({ domain: 'YOUR_DOMAIN', secureURLToken: 'YOUR_SECURE_URL_TOKEN' });
-
生成处理后的URL:
const url = client.buildURL('example-image.jpg', { w: 100, h: 150, fit: 'crop' }); console.log(url); // 输出类似 https://YOUR_DOMAIN/example-image.jpg?w=100&h=150&fit=crop 的URL
以上两种方法都可以让你轻松地对图片进行动态处理,而无需手动下载和修改图片文件。希望这些示例能帮助你在Node.js项目中实现高效的图片处理功能。
七牛?
七牛目前在用免费的,感觉很好。