美文网首页iOS开发转发iOS开发锦集iOS开发笔记
iOS 马甲包(一)图片轻量级压缩改变hash值

iOS 马甲包(一)图片轻量级压缩改变hash值

作者: 1剑天下 | 来源:发表于2018-08-29 16:05 被阅读238次

    图片轻量级压缩主要是通过imagemagick软件来实现,我们通过homebrew软件来安装
    1. 安装homebrew

    命令行输入:/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
    
    /usr/bin/ruby -e "$(curl -fsSL [https://raw.githubusercontent.com/Homebrew/install/master/install)](https://raw.githubusercontent.com/Homebrew/install/master/install))"
    
    

    下载进度 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/lixuewen/Library/Caches/Homebrew ==> /usr/bin/sudo /usr/sbin/chown lixuewen /Users/lixuewen/Library/Caches/Homebrew ==> Downloading and installing Homebrew... remote: Counting objects: 108116, done. remote: Compressing objects: 100% (17/17), done. remote: Total 108116 (delta 5), reused 14 (delta 5), pack-reused 108093 Receiving objects: 100% (108116/108116), 24.52 MiB | 34.00 KiB/s, done. Resolving deltas: 100% (79025/79025), done. From https://github.com/Homebrew/brew

    如果提示出错了Error: /usr/local/Cellar is not writable. You should change the
    ownership and permissions of /usr/local/Cellar back to your
    user account:

    输入下面的命令行 sudo chown -R $(whoami) /usr/local/Cellar
    

    然后继续安装输入上面的安装指令
    检测是否安装成功

    brew
    

    如果安装成功了,会返回如下命令

      brew search [TEXT|/REGEX/]
      brew info [FORMULA...]
      brew install FORMULA...
      brew update
      brew upgrade [FORMULA...]
      brew uninstall FORMULA...
      brew list [FORMULA...]
    
    Troubleshooting:
      brew config
      brew doctor
      brew install --verbose --debug FORMULA
    
    Contributing:
      brew create [URL [--no-fetch]]
      brew edit [FORMULA...]
    
    Further help:
      brew commands
      brew help [COMMAND]
      man brew
    https://docs.brew.sh
    

    2 安装安装x11,因为muntain lion已经删除了x11
    https://www.xquartz.org

    3 安装完xQuartz之后开始安装ghostscript,这个linux本来就安装了,但是mac没

    brew install ghostscript
    

    Updating Homebrew... ==> Installing dependencies for ghostscript: jpeg, libtiff, little-cms2 ==> Installing ghostscript dependency: jpeg ==> Downloading https://homebrew.bintray.com/bottles/jpeg-9c.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring jpeg--9c.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/jpeg/9c: 21 files, 724.5KB ==> Installing ghostscript dependency: libtiff ==> Downloading https://homebrew.bintray.com/bottles/libtiff-4.0.9_4.high_sierra.bottle.tar ######################################################################## 100.0% ==> Pouring libtiff--4.0.9_4.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/libtiff/4.0.9_4: 246 files, 3.5MB ==> Installing ghostscript dependency: little-cms2 ==> Downloading https://homebrew.bintray.com/bottles/little-cms2-2.9.high_sierra.bottle.1.t ######################################################################## 100.0% ==> Pouring little-cms2--2.9.high_sierra.bottle.1.tar.gz 🍺 /usr/local/Cellar/little-cms2/2.9: 18 files, 1MB ==> Installing ghostscript ==> Downloading https://homebrew.bintray.com/bottles/ghostscript-9.23.high_sierra.bottle.ta ######################################################################## 100.0% ==> Pouring ghostscript--9.23.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/ghostscript/9.23: 679 files, 64.3MB

    4.最后安装imagemagick

     brew install imagemagick
    

    输入命令进行压缩

    $ cd /Users/lixuewen/Desktop/未命名文件夹\ 2 
    $ find . -iname "*.png" -exec echo {} \; -exec convert {} -quality 95 {} \;
    

    一些其他用法

    更改文件类型
    $  convert input.jpg output.png
     1)增加有色边
    convert -bordercolor red -border 25x25 image.jpg image.gif
     2)加亮或变暗图片边缘,以增强3D效果
    convert -raise 25 image.jpg image.gif
     3)在图片周围增加装饰性框架。
    convert -mattecolor gray -frame 25x25 image.jpg image.gif
     4)在图片边缘增加升、降斜角
    convert -mattecolor gray -frame 25x25+0+25 image.jpg image.gif
    convert -mattecolor gray -frame 25x25+25+0 image.jpg image.gif
    5)将gif文件分析为一系列的单个图片
    convert animation.gif frame%02d.gif
    6)创建一张空白图片
    convert -size 800x600 xc:"#ddddff" ltblue.ppm
    convert -size 800x600 null:white white.ppm
    convert in.png -threshold 100% black.ppm #<--与in.png同大小
    

    Mac: 文件校验终端命令查看文件哈希值,md5

    `MD5`
    $ md5 文件路径
    
    `SHA1`
    $ shasum 文件路径 
    或者
    $ openssl dgst -sha1 文件路径
    
    `SHA256`
    openssl dgst -sha256 文件路径
    

    例:

    bogon:未命名文件夹 2 lixuewen$ convert ert.jpg 111.png
    bogon:未命名文件夹 2 lixuewen$ shasum /Users/lixuewen/Desktop/未命名文件夹\ 2/ert.jpg 
    `d0b0df3d1c1c72f7ea8f8512fb99e8aa7815fbc2`  /Users/lixuewen/Desktop/未命名文件夹 2/ert.jpg
    bogon:未命名文件夹 2 lixuewen$ shasum /Users/lixuewen/Desktop/未命名文件夹\ 2/111.png 
    `0a51d4c26c9102132038f54986ca2ff575b7e6ab`  /Users/lixuewen/Desktop/未命名文件夹 2/111.png
    bogon:未命名文件夹 2 lixuewen$ find . -iname "*.png" -exec echo {} \; -exec convert {} -quality 95 {} \;
    ./111.png
    bogon:未命名文件夹 2 lixuewen$ shasum /Users/lixuewen/Desktop/未命名文件夹\ 2/111.png 
    `392477f3b6ecdb2baeee903117a22731d26a1dba`  /Users/lixuewen/Desktop/未命名文件夹 2/111.png
    
    bogon:未命名文件夹 2 lixuewen$ 
    

    相关文章

      网友评论

        本文标题:iOS 马甲包(一)图片轻量级压缩改变hash值

        本文链接:https://www.haomeiwen.com/subject/lynfwftx.html