LoginSignup
59
40

More than 3 years have passed since last update.

Mac テスト用の画像を生成する

Last updated at Posted at 2018-05-19

背景

ファイルのアップロード機能を作った時などに、アップロード用のテスト画像を用意するのが手間でした。
開発環境ならネットから適当に拾ってきた画像で良いのですが、
ステージングなどでテストするときに趣味趣向がバレバレになってしまいます。これはまずいです。

目的

テスト用の画像を生成する。

導入

ImageMagick(イメージマジック)という画像操作ライブラリをインストールします。

$ brew install imagemagick

$ magick -version
Version: ImageMagick 7.0.7-33 Q16 x86_64 2018-05-17 https://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: https://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib

Homebrew入っていない人はココからインストールしましょう。

ファイルはコマンドを実行した場所に画像が生成されます。

$ mkdir sample_image; cd sample_image

お試しする場合はテスト用ディレクトリを作成しておきましょう!

単色の画像ファイルを作成

$ magick -size 400x300 canvas:tomato bg_tomato.png

bg_tomato.png

数値入りの画像を作成

$ magick -size 400x300 -background tomato -fill black -gravity center -pointsize 70 label:"000" bg_tomato_000.png

bg_tomato_000.png

連番の画像を作成

コピペすれば、10枚の連番画像が3セットの色違いを生成できます。

for i in `seq -f %03g 1 10`
do
  magick -size 400x300 -background tomato -fill black -gravity center -pointsize 100 label:$i bg_tomato_$i.png;
done

for i in `seq -f %03g 1 10`
do
  magick -size 800x600 -background teal -fill black -gravity center -pointsize 200 label:$i bg_teal_$i.png;
done

for i in `seq -f %03g 1 10`
do
  magick -size 1920x1080 -background skyblue -fill black -gravity center -pointsize 400 label:$i bg_skyblue_$i.png;
done

ファイル枚数が多いので Dropbox に上げてみました。

テスト用にURLだけ欲しい時

## skyblue

https://user-images.githubusercontent.com/35098175/52777835-0d663b80-3088-11e9-84db-ea51ec5bde71.png
https://user-images.githubusercontent.com/35098175/52777849-13f4b300-3088-11e9-85bd-383174d7348d.png
https://user-images.githubusercontent.com/35098175/52777851-148d4980-3088-11e9-83d9-f8fcdab14cc1.png
https://user-images.githubusercontent.com/35098175/52777853-148d4980-3088-11e9-96c2-2bb2f2888e33.png
https://user-images.githubusercontent.com/35098175/52777854-1525e000-3088-11e9-91a2-adf59c3f4953.png
https://user-images.githubusercontent.com/35098175/52777855-1525e000-3088-11e9-9cd3-1650e8381815.png
https://user-images.githubusercontent.com/35098175/52777856-1525e000-3088-11e9-9a9f-605fd0fe29ce.png
https://user-images.githubusercontent.com/35098175/52777857-15be7680-3088-11e9-9587-23f68734e986.png
https://user-images.githubusercontent.com/35098175/52777858-15be7680-3088-11e9-87cb-c9dff84a4d34.png
https://user-images.githubusercontent.com/35098175/52777860-15be7680-3088-11e9-92f3-dd06fd0c2a47.png

## teal

https://user-images.githubusercontent.com/35098175/52777916-3a1a5300-3088-11e9-93da-92f978fbbcc3.png
https://user-images.githubusercontent.com/35098175/52777918-3a1a5300-3088-11e9-887a-a40f5e0bc3dd.png
https://user-images.githubusercontent.com/35098175/52777920-3a1a5300-3088-11e9-8ba6-d8dfd6a3753e.png
https://user-images.githubusercontent.com/35098175/52777921-3ab2e980-3088-11e9-8109-8b6beeb202be.png
https://user-images.githubusercontent.com/35098175/52777922-3ab2e980-3088-11e9-8626-299ee4def348.png
https://user-images.githubusercontent.com/35098175/52777923-3ab2e980-3088-11e9-9f44-95be06d75f59.png
https://user-images.githubusercontent.com/35098175/52777924-3b4b8000-3088-11e9-9595-baf0855b3afa.png
https://user-images.githubusercontent.com/35098175/52777926-3b4b8000-3088-11e9-9949-f24216b43af0.png
https://user-images.githubusercontent.com/35098175/52777928-3be41680-3088-11e9-94d8-b470415f428f.png
https://user-images.githubusercontent.com/35098175/52777929-3be41680-3088-11e9-82c3-44a2770a83cb.png

## tomato

https://user-images.githubusercontent.com/35098175/52777943-42728e00-3088-11e9-83a1-07866cc6407c.png
https://user-images.githubusercontent.com/35098175/52777945-42728e00-3088-11e9-87c3-0923c8c13dc8.png
https://user-images.githubusercontent.com/35098175/52777946-430b2480-3088-11e9-8f0e-08c442a56967.png
https://user-images.githubusercontent.com/35098175/52777947-430b2480-3088-11e9-87bb-39bf771cfa09.png
https://user-images.githubusercontent.com/35098175/52777949-430b2480-3088-11e9-853e-ba0b7c6d50b9.png
https://user-images.githubusercontent.com/35098175/52777950-430b2480-3088-11e9-9a29-3a312c66161b.png
https://user-images.githubusercontent.com/35098175/52777951-43a3bb00-3088-11e9-902a-8b4fb36394d9.png
https://user-images.githubusercontent.com/35098175/52777952-443c5180-3088-11e9-96c8-b3b3bf1c2faf.png
https://user-images.githubusercontent.com/35098175/52777955-443c5180-3088-11e9-80f8-252019540130.png
https://user-images.githubusercontent.com/35098175/52777956-443c5180-3088-11e9-80f1-e56f5c242923.png
59
40
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
59
40