All Projects → consatan → Weibo_image_uploader

consatan / Weibo_image_uploader

Licence: bsd-3-clause
PHP 实现的微博图床上传轮子

Projects that are alternatives of or similar to Weibo image uploader

Weibo Picture Store
🖼 新浪微博图床 Chrome/Firefox 扩展,支持同步到微相册
Stars: ✭ 624 (+383.72%)
Mutual labels:  sina, picture, weibo
Flickrsync
A command line tool to synchronise, upload, download, pictures between the local file system and Flickr. Image hash signature of the picture is used to uniquely identify the image.
Stars: ✭ 14 (-89.15%)
Mutual labels:  image, picture
Vue Picture Input
Mobile-friendly picture file input Vue.js component with image preview, drag and drop, EXIF orientation, and more
Stars: ✭ 862 (+568.22%)
Mutual labels:  image, picture
Gopherkon
Go mascot image constructor. Create your cute own gopher.
Stars: ✭ 86 (-33.33%)
Mutual labels:  image, picture
Uppload
📁 JavaScript image uploader and editor, no backend required
Stars: ✭ 1,673 (+1196.9%)
Mutual labels:  image, uploader
Tysnapshotscroll
一句代码保存截图,将 UIScrollView UITableView UICollectionView UIWebView WKWebView 网页 保存 为 长图 查看。Save the scroll view page as an image,support UIScrollView,UITableView,UICollectionView,UIWebView,WKWebView.(Support iOS13)
Stars: ✭ 709 (+449.61%)
Mutual labels:  image, picture
React Images Uploading
The simple images uploader applied Render Props pattern that allows you to fully control UI component and behaviors.
Stars: ✭ 80 (-37.98%)
Mutual labels:  image, uploader
Renderhelp
⚡️ 可编程渲染管线实现,帮助初学者学习渲染
Stars: ✭ 494 (+282.95%)
Mutual labels:  image, picture
Angular File Uploader
Angular file uploader is an Angular 2/4/5/6/7/8/9/10 + file uploader module with Real-Time Progress Bar, Responsive design, Angular Universal Compatibility, localization and multiple themes which includes Drag and Drop and much more.
Stars: ✭ 92 (-28.68%)
Mutual labels:  image, uploader
Grid
The Guardian’s image management system
Stars: ✭ 1,380 (+969.77%)
Mutual labels:  image, picture
Gis
gis (go image server) go 实现的图片服务,实现基本的上传,下载,存储,按比例裁剪等功能
Stars: ✭ 108 (-16.28%)
Mutual labels:  image, picture
Html To Image
✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
Stars: ✭ 595 (+361.24%)
Mutual labels:  image, picture
Weibospider
⚡ A distributed crawler for weibo, building with celery and requests.
Stars: ✭ 4,670 (+3520.16%)
Mutual labels:  sina, weibo
React Viewer
react image viewer, supports rotation, scale, zoom and so on
Stars: ✭ 502 (+289.15%)
Mutual labels:  image, picture
V Viewer
Image viewer component for vue, supports rotation, scale, zoom and so on, based on viewer.js
Stars: ✭ 1,776 (+1276.74%)
Mutual labels:  image, picture
Color.js
Extract colors from an image (0.75 KB) 🎨
Stars: ✭ 42 (-67.44%)
Mutual labels:  image, picture
Pyinstastories
Python script to download Instagram stories from Instagram users.
Stars: ✭ 260 (+101.55%)
Mutual labels:  image, picture
React Image Magnify
A responsive image zoom component designed for shopping sites.
Stars: ✭ 391 (+203.1%)
Mutual labels:  image, picture
React Responsive Picture
A future-proof responsive image component that supports latest Picture specification
Stars: ✭ 91 (-29.46%)
Mutual labels:  image, picture
Wecase
The Linux Sina Weibo Client
Stars: ✭ 108 (-16.28%)
Mutual labels:  sina, weibo

PHP 实现的微博图床上传轮子

安装

要求
  • PHP 7.0 以上版本
  • json 扩展
  • openssl 扩展

PHP 5.5, 5.6 版本请使用 0.5 版本

使用 composer (推荐)

composer require consatan/weibo_image_uploader

从 Github 上下载

git clone https://consatan.github.com/weibo_image_uploader.git

使用示例

<?php
// 引入 composer autoload
require './vendor/autoload.php';

$weibo = new Consatan\Weibo\ImageUploader\Client();

// 默认返回的是 https 协议的图床 URL,调用该方法返回的是 http 协议的图床 URL
// $weibo->useHttps(false);

// 上传示例图片
$url = $weibo->upload('./example.jpg', '微博帐号', '微博帐号密码');

// 输出新浪图床 URL
echo $url . PHP_EOL;

使用说明

构造函数可传递 \Psr\Cache\CacheItemPoolInterface\GuzzleHttp\ClientInterface,默认情况下使用文件缓存 cookie 信息,存储在项目根目录的 cache/weibo 文件夹下,缓存的 key 使用 md5 后的微博用户名,可根据需求将缓存保存到其他适配器中,具体参见 \Symfony\Cache\Adapter

关于验证码问题(issue #3),可查看 example/cli.php 示例代码

Client::upload 方法的第四个参数允许传递 Guzzle request 的参数数组,具体见 Request Options,通过该参数可实现切换代理等操作,如下例:

<?php

// 文件路径
$url1 = $weibo->upload('./example.jpg', '微博帐号1', '密码');
// 同一用户名只有第一次上传需要登入,之后使用缓存的登入 cookie 进行上传
// 如果使用 cookie 上传失败,将尝试重新登入一次,还是失败的话抛出异常
// 除非使用的是无法持久化保存的缓存适配器(如 ArrayAdapter)
// 否则以后同一用户名都将使用缓存的 cookie 进行登入
// echo $weibo->upload('./example.jpg', '微博帐号1', '密码');

// resource
$url2 = $weibo->upload(fopen('./example.jpg', 'r'), '微博帐号2', '密码', [
    'proxy' => 'http://192.168.1.100:8080'
]);

// 字符串
$url3 = $weibo->upload(file_get_contents('./example.jpg'), '微博帐号3', '密码', [
    'proxy' => 'http://192.168.1.200:8090'
]);

// \Psr\Http\Message\StreamInterface
$url4 = $weibo->upload(\GuzzleHttp\Psr7\stream_for(file_get_contents('./example.jpg')), '微博帐号4', '密码', [
    'proxy' => 'http://192.168.1.250:9080'
]);
水印选项
// 开启水印
$url = $weibo->upload('./example.jpg', '微博帐号', '密码', ['mark' => true]);

// 水印位置
$url = $weibo->upload('./example.jpg', '微博帐号', '密码', [
    'mark' => true,
    'markpos' => Consatan\Weibo\ImageUploader\Client::MARKPOS_BOTTOM_CENTER,
]);

// 可使用任意的水印暱称(也许以后的版本就会和谐了)
$url = $weibo->upload('./example.jpg', '微博帐号', '密码', ['mark' => true, 'nickname' => '任意暱称']);
获取其他尺寸的图片链接
// 默认使用 large (原始)尺寸,此处使用 thumbnail (缩略图) 尺寸
$url = $weibo->upload('./example.jpg', '微博帐号', '密码', [
    'size' => Consatan\Weibo\ImageUploader\Client::IMAGE_SIZE_THUMBNAIL
]);

// 获取多个尺寸的图片链接
$urls = $weibo->upload('./example.jpg', '微博帐号', '密码', ['size' => [
    Consatan\Weibo\ImageUploader\Client::IMAGE_SIZE_SMALL,
    Consatan\Weibo\ImageUploader\Client::IMAGE_SIZE_LARGE,
    Consatan\Weibo\ImageUploader\Client::IMAGE_SIZE_THUMBNAIL,
]]);
// 返回
// array (
//   'small' => 'https://ws2.sinaimg.cn/small/0068M0xKgy1fetd4l7x6vj30bo0bximx.jpg',
//   'large' => 'https://ws2.sinaimg.cn/large/0068M0xKgy1fetd4l7x6vj30bo0bximx.jpg',
//   'thumbnail' => 'https://ws2.sinaimg.cn/thumbnail/0068M0xKgy1fetd4l7x6vj30bo0bximx.jpg',
// )
upload 方法中,$config 和 $option 参数位置可调换
// 以下 2 种传参顺序最终效果是一致的
$url = $weibo->upload('./example.jpg', '微博帐号', '密码', [
    'size' => Consatan\Weibo\ImageUploader\Client::IMAGE_SIZE_THUMBNAIL
], [
    'proxy' => 'http://192.168.1.250:9080'
]);

$url = $weibo->upload('./example.jpg', '微博帐号', '密码', [
    'proxy' => 'http://192.168.1.250:9080'
], [
    'size' => Consatan\Weibo\ImageUploader\Client::IMAGE_SIZE_THUMBNAIL
]);

抛出的所有异常都可通过 \Consatan\Weibo\ImageUploader\Exception\ImageUploaderException 接口捕获, 实现该接口的异常都在 src/Exception 目录下。

Todo

  • [ ] 单元测试
  • [x] 获取其他规格的图片 URL(如,small, thumbnail...)
  • [x] 添加水印选项
  • [x] 实现验证码输入(用户输入)

参考

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].