Shell调用ImageMagick转换图片格式属性以与JAVA兼容

JAVA的图形IO原生并不兼容colour space属性为"CMYK",color profile cii为"Japan Color 2001 Coated"格式的文件。此类图片在没有兼容性处理的JAVA程序中直接上传下载都会报错(https://stackoverflow.com/questions/3123574/how-to-convert-from-cmyk-to-rgb-in-java-correctly)。以下Shell脚本借助`ImageMagick'开源库,将图片属性转换成兼容的"sRGB",以防止图片文件在JAVA程序中的传输报错。

#!/usr/bin/env bash
# author    : 蛙鳜鸡鹳狸猿
# create_ts : 2020-07-01
# program   : convert properties of a image file to be compatible with JAVA

# Image color profile `cii' of "Japan Color 2001 Coated" and colour space of "CMYK" is not compatible with JAVA
# thus causing program BUGs of JAVA-based image handler system.
# This script is to convert its properties of a image into compatible format.

# This script relays on OS program of `ImageMagick', thanks to the open source developers.
# See also:
#    http://www.imagemagick.org/
# You can easily install `ImageMagick' by
#        > yum install ImageMagick
# on rpm series OS and
#        > apt install imagemagick
# on deb series OS.

# *******************************************************************************
#
#                        |\_/|
#                        | ・x・ |
#               \_____/    |
#                 |         |    ニャンー ニャンー
#                \       ノ 
#             ((( (/ ̄ ̄ ̄ ̄(/ヽ)
#
# User-definition Variables Area
#
folder_source=${1:-'/img'}
folder_backup=${2:-'/img_backup'}
#
# *******************************************************************************


function program_usage() {
    echo -e '\nProgram can get up to 2 valid args(the rest is ignored) from command line.'
    echo "* Input blank string('' or \"\") as placeholder when an arg takes default value and with arg of defined value following *"
    echo ''
    echo -e "\t\$1 -> Source direction of image files be storing. Default value: /img."
	echo -e "\t\$2 -> Backup direction of image files to be converted. Default value: /img_backup.\n"
}

function get_incompatible_image() {
    identify -verbose $1 | grep icc > /dev/null
    return $?
}

function convert_incompatible_image() {
    convert -colorspace sRGB -strip "$1" "$2" &> /dev/null
    return $?
}

function main() {
    case $1 in
    -h|--help)
        program_usage
        exit 0
        ;;
    esac

    local dir_source=${folder_source%/}
    local dir_backup=${folder_backup%/}
    local IFS=$'\n'

    for img in $(ls ${dir_source})
    do
        local img_source_path=${dir_source}/${img}
        get_incompatible_image ${img_source_path}
        if [ $? -eq 0 ]; then
            local img_backup_path=${dir_backup}/${img}
            mv ${img_source_path} ${img_backup_path} && convert_incompatible_image ${img_backup_path} ${img_source_path}
            if [ $? -ne 0 ]; then
                echo "convert file ${img_source_path} failed..."
                continue
            fi
        fi
    done
}


main "$1"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
D&Z工作室倾情奉献 欢迎使用DateCracker 2001 许多共享软件都有时间上的限制,本程序正是象“时光倒流”等程序一样,通过修改系统时间达到破解时间限制的目的。当然,使用手动修改也是可以的,但每次使用都要修改而且使用完又要把时间改回,更糟糕的是有些软件一旦发现过期,重装都没有用了。本人就是因为使用没有注册码的Dreamwaver,被它反复折腾了很久而产生做这个软件的念头的。 此类程序又很多,但DateCracker 2001是最有特色,也最成熟的。 使用DateCracker 2001的理由: 1、使用极为方便,让你都感觉不到时间被修改。 2、两种破解方式,功能强大 (1)快捷方式替换(Lnk修改):自动生成一个新的Cracked快捷方式,点击直接破解运行。 (2)EXE文件替换:象WinRAR、UltraEditor这类程序,往往会在资源管理器的右键菜单中添加选项、而且还会有相应的文件关联,这时如果你要直接点击菜单或打开关联的文件就需要使用EXE文件替换了。DateCracker 2001将使用偷天换日之术,将EXE文件替换,让你使用自如! 3、漂亮的界面、而且支持换肤! 4、完全的绿色软件。 使用方法: 添加需破解的程序时只需将它的快捷方式或EXE文件拖到托盘中就行,如果模式为自动的话:快捷方式添加后DateCracker 2001将使用快捷方式替换模式,而EXE文件添加进去的话DateCracker 2001将使用EXE文件替换模式,一旦添加,以后直接运行,系统时间即更改,当程序运行完毕,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值