sh 用于将图像上传到imgur.com的Shell脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 用于将图像上传到imgur.com的Shell脚本相关的知识,希望对你有一定的参考价值。

#!/bin/sh
#
# Upload image(s) to imgur.com
# Copyright (C) 2014  Vivien Didelot <vivien@didelot.org>
# Licensed under GPL version 3, see http://www.gnu.org/licenses/gpl.txt
#
# Requires "jshon":
#   http://kmkeen.com/jshon/
#
# Alternatives, which suck:
#   http://imgur.com/tools/imgurbash.sh
#   https://raw.githubusercontent.com/JonApps/imgur-screenshot/master/imgur-screenshot.sh
#
# Usage:
#   imgur <file>...
#   Specify <file> as '-' for standard input.
#
# Examples:
#
# * Upload several images:
#   imgur foo.png bar.png
#
# * Take a screenshot and upload it:
#   import png:- | imgur -
#
# * Copy the url to clipboard:
#   imgur <file> | xclip
#
# * Open the result in a web browser:
#   imgur <file> | xargs firefox
#
# * Quick use (no installation):
#   curl -s https://gist.githubusercontent.com/vivien/9768953/raw/imgur | sh -s <file>

# API key from Alan@imgur.com, see imgurbash.sh
KEY=b3625162d3418ac51a9ee805b1840452

die () {
  echo "$1" >&2
  exit 1
}

# Syntax check
[ $# -lt 1 ] && die "usage: imgur <file>... (use - for stdin)"

# Upload every file given as argument
for IMG in "$@"
do
  # A more verbose version of `curl -s [...] | jshon -Q -e rsp -e image -e original_image -u`

  RESP="`curl -sS -F key=$KEY -H 'Expect: ' -F "image=@$IMG" http://imgur.com/api/upload.json 2>&1`"
  [ $? -ne 0 ] && die "$IMG: $RESP"

  URL=`echo "$RESP" | jshon -Q -e rsp -e image -e original_image -u`
  [ -z "$URL" ] && die "$IMG: `echo "$RESP" | jshon -e rsp -e image -e error_msg -u`"

  echo $URL
done

# vim: et ts=2 sw=2

以上是关于sh 用于将图像上传到imgur.com的Shell脚本的主要内容,如果未能解决你的问题,请参考以下文章

sh 一个小的shell脚本,显示如何将文件上传到S3。用法可以用于ELB

无法将 imgur 上的 gif 嵌入 github 上的 README.md

用于验证码识别的训练 Tesseract

用于将 svg 图像上传到 AWS S3 的内容类型

使用正则表达式,我可以将网址更改为 html 图像标签 [关闭]

如何将图像放在图像中颤动