Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ImageMagick実践入門 画像加工サーバを作ってみよう / ImageMagick an...
Search
Hiroshi Shimoju
October 29, 2017
Technology
0
3.4k
ImageMagick実践入門 画像加工サーバを作ってみよう / ImageMagick and image server
新卒エンジニア研修の座学でImageMagickの話をしました。
Hiroshi Shimoju
October 29, 2017
Tweet
Share
More Decks by Hiroshi Shimoju
See All by Hiroshi Shimoju
プロダクト開発エンジニアからSREへの挑戦 / backend-engineer-and-sre
shimoju
0
1.1k
実践 Heroku Enterprise / Unite Heroku Enterprise
shimoju
0
120
Herokuで本番運用する技術 / Heroku production
shimoju
2
6k
Web開発研修 イントロダクション / Web development training introduction
shimoju
0
11k
データ分析その前に〜Redashでデータ可視化からはじめよう / Data visualization by Redash
shimoju
1
1.9k
iOSアプリのテストをやってみて考えたこと / Testing iOS app
shimoju
1
150
Other Decks in Technology
See All in Technology
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
180
スクラム成熟度セルフチェックツールを作って得た学びとその活用法
coincheck_recruit
1
140
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
150
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
520
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
5
610
Engineer Career Talk
lycorp_recruit_jp
0
140
Taming you application's environments
salaboy
0
180
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Scaling GitHub
holman
458
140k
Writing Fast Ruby
sferik
627
61k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
We Have a Design System, Now What?
morganepeng
50
7.2k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Designing the Hi-DPI Web
ddemaree
280
34k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Transcript
ը૾ՃαʔόΛ࡞ͬͯΈΑ͏ Լॏതࢿ(.01FQBCP *OD ৽ଔΤϯδχΞݚम࠲ֶ *NBHF.BHJDL࣮ફೖ
ΤϯδχΞ ೖࣾɾ৽ଔظ Լॏതࢿ!TIJNPKV@ &$ࣄۀ෦46;63*νʔϜ TIJNPKVPSH
None
None
͓͠ͳ͕͖ wࠓͷΰʔϧ w46;63*ͱը૾ॲཧ w*NBHF.BHJDLΛ৮ͬͯΈΑ͏ wը૾ՃαʔόΛ࡞ͬͯΈΑ͏
ࠓͷΰʔϧ w*NBHF.BHJDLΛ༻ͨ͠ը૾ՃΛͬͯΈͯɺ wը૾ॲཧͨͷͦ͠͏ʂͬͯͳΔ͜ͱ wഎޙʹ͋ΔࣜɺମܥతͳཧղͷͨΊͷཧʹ͍ͭ ͯ ൃදऀͷࣝෆʹΑΓ ѻ͍·ͤΜ
46;63*ͱը૾ॲཧ
46;63*ͱը૾ॲཧ wΞοϓ͞Εͨը૾ΛΞΠςϜը૾ ͱ߹ͯ͠αϜωΠϧΛ࡞Δ w5γϟπͷγϫʹ߹Θͤͯը૾Λ มܗ σΟεϓϨΠεϝϯτϚο ϐϯά ͤͨ͞Γ wӨΛ͚ͭͨΓ৭Λมͨ͠Γ
46;63*ͱը૾ॲཧ wΞοϓ͞Εͨը૾ΛΞΠςϜը૾ ͱ߹ͯ͠αϜωΠϧΛ࡞Δ w5γϟπͷγϫʹ߹Θͤͯը૾Λ มܗ σΟεϓϨΠεϝϯτϚο ϐϯά ͤͨ͞Γ wӨΛ͚ͭͨΓ৭Λมͨ͠Γ
*NBHF.BHJDLΛ ৮ͬͯΈΑ͏
ͱΓ͋͑ͣΠϯετʔϧ $ brew install imagemagick OR $ sudo apt-get install
-y imagemagick OR $ sudo yum -y install ImageMagick
*NBHF.BHJDL wը૾Ճͱ͍͑͜Εͱ͍͏༗໊ϥΠϒϥϦ wϝδϟʔ͔ΒϚΠφʔ·Ͱ͞·͟·ͳը૾ܗࣜʹରԠ wػೳ͕ଟ͗ͯ͢੬ऑੑͨͼͨͼൃݟ͞ΕΔ͘Β͍ʜ w$Ͱ࣮͞Εɺଟ͘ͷݴޠͰόΠϯσΟϯά͕͋Δ w3VCZɿSNBHJDL NJOJ@NBHJDLHFN w1)1ɿ*NBHJDL֦ுϥΠϒϥϦͳͲ
ίϚϯυ wJNBHFNBHJDLͱ͍͏ίϚϯυͳ͍ wػೳ͝ͱʹDPOWFSUJEFOUJGZͳͲͷίϚϯυʹΘ͔Ε͍ͯΔ wͨͩ͠ɺ*NBHF.BHJDL͔Βͯ͢NBHJDLίϚϯυͷγϯϘ ϦοΫϦϯΫʹͳ͍ͬͯΔ
*NBHF.BHJDL 6CVOUV $ ls -Alh /usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16 total 88K -rwxr-xr-x 1
root root 6.3K Jul 31 13:22 animate -rwxr-xr-x 1 root root 6.3K Jul 31 13:22 compare -rwxr-xr-x 1 root root 6.3K Jul 31 13:22 composite -rwxr-xr-x 1 root root 6.3K Jul 31 13:22 conjure -rwxr-xr-x 1 root root 6.3K Jul 31 13:22 convert -rwxr-xr-x 1 root root 6.3K Jul 31 13:22 display -rwxr-xr-x 1 root root 6.3K Jul 31 13:22 identify -rwxr-xr-x 1 root root 6.3K Jul 31 13:22 import -rwxr-xr-x 1 root root 6.3K Jul 31 13:22 mogrify -rwxr-xr-x 1 root root 6.3K Jul 31 13:22 montage -rwxr-xr-x 1 root root 6.3K Jul 31 13:22 stream
*NBHF.BHJDL .BD)PNFCSFX $ ls -Alh /usr/local/Cellar/imagemagick/7.0.7-7/bin | grep -v config
total 64 lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 animate -> magick lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 compare -> magick lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 composite -> magick lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 conjure -> magick lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 convert -> magick lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 display -> magick lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 identify -> magick lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 import -> magick -r-xr-xr-x 1 shimoju admin 18K 10 9 18:25 magick lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 magick-script -> magick lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 mogrify -> magick lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 montage -> magick lrwxr-xr-x 1 shimoju admin 6B 10 7 21:02 stream -> magick
JEFOUJGZ wը૾ͷใΛग़ྗͰ͖Δ wαΠζΛͬ͞ͱΓ͍ͨͱ͖ͱ͔ɺ wେྔͷը૾ͷத͔ΒαΠζ͕ҧ͏ͷΛ୳ͨ͠Γͱ͔
JEFOUJGZ $ identify *.jpg original.jpg JPEG 800x533 800x533+0+0 8-bit sRGB
104823B 0.000u 0:00.000 resize.jpg JPEG 400x267 400x267+0+0 8-bit sRGB 37116B 0.000u 0:00.000 ϑΥʔϚοτจࣈྻ͜͜ΒΜࢀরɿhttps://www.imagemagick.org/script/escape.php $ identify -format '{"width": %w, "height": %h}' *.jpg | jq { "width": 800, "height": 533 } $ identify -format '%wx%h %f\n' *.jpg | grep -v 800x533 200x200 crop.jpg
DPOWFSU w͞·͟·ͳը૾ՃΛߦ͑Δɺ*NBHF.BHJDLͷϝΠϯίϚϯυ wҎ߱ͯ͢DPOWFSUίϚϯυΛѻ͍͖ͬͯ·͢
దͳը૾Λ༻ҙ͠·͢ ਖ਼ํܗ͡Όͳ͍΄͏͕͍͍Ͱ͢ɻ͜ͷը૾YQY ग़యɿIUUQTXXXQBLVUBTPDPNQPTUIUNM
ճస SPUBUF ճస $ convert -rotate 90 original.jpg rotate.jpg ্Լస
$ convert -flip original.jpg flip.jpg ࠨӈస $ convert -flop original.jpg flop.jpg ্Լࠨӈస $ convert -flip -flop original.jpg flipflop.jpg
None
αϯϓϧ TBNQMF ϐΫηϧΛؒҾ͘ $ convert -sample 10% original.jpg sample.jpg 10%ʹͳΔΑ͏ʹϐΫηϧΛؒҾ͍ͨ͋ͱɺ1000%ʹͳΔΑ͏ʹ֦େ
→ݩը૾ͱಉ͡αΠζͰϞβΠΫ͕͔͔Δ $ convert -sample 10% -sample 1000% original.jpg sample.jpg
None
ϦαΠζ SFTJ[F σϑΥϧτͰΞεϖΫτൺΛม͑ͳ͍ɿࢦఆͨ͠෯ɾߴ͞ʹऩ·ΔΑ͏ʹϦαΠζ͞ΕΔ $ convert -resize 400x400 original.jpg resize.jpg $
identify resize.jpg resize.jpg JPEG 400x267 400x267+0+0 8-bit sRGB 37116B 0.000u 0:00.000 !Λ͚ͭΔͱΞεϖΫτൺΛແࢹͯ͠ࢦఆͨ͠ʹϦαΠζ͢Δ $ convert -resize 400x400! original.jpg resize2.jpg ෯·ͨߴ͞ͷΈࢦఆͰ͖Δ $ convert -resize 400x original.jpg resize3.jpg
None
Τοδݕग़ FEHF ෆ࿈ଓʹมԽ͍ͯ͠ΔՕॴΛݕग़͢Δ $ convert -edge 5 original.jpg edge.jpg ΛมԽͤͯ͞ΈΑ͏
$ convert -edge 10 original.jpg edge.jpg $ convert -edge 1 original.jpg edge.jpg
None
Γൈ͖ DSPQ -gravityͰج४Λࢦఆ -crop widthxheightͰΓൈ͘αΠζΛࢦఆ +/-Ͱج४͔Βͷx,y࠲ඪΛࢦఆ $ convert -gravity center
-crop 200x200+0+0 original.jpg crop.jpg ը૾ӈ্Λج४ʹɺxʹ140px,yʹ50pxҠಈ͠ɺͦͷ͔Β200x200pxΓൈ͘ $ convert -gravity northeast -crop 200x200+140+50 original.jpg crop.jpg
None
ృΓ͠ FYUFOU ࢦఆͨ͠αΠζʹͳΔΑ͏ʹ༨നΛՃ͢Δ ༨നͷ৭-backgroundͰࢦఆͰ͖Δ ਖ਼ํܗͷαΠζ͕ඞཁͳͷʹ4:3ͷը૾͔͠ͳ͍ͱ͔ʹศར $ convert -background black -gravity
center \ -extent 800x800 original.jpg extent.jpg PNG(ಁա͕ѻ͑ΔϑΥʔϚοτ)Ͱ͋ΕtransparentͰಁաͰ͖Δ $ convert -background transparent -gravity north \ -extent 1000x1000 original.jpg extent.png
None
ͦΖͦΖ߹ͨ͘͠ ͳ͖ͬͯͨΑͶʁ
ͦͷલʹจࣈͷը૾Λ࡞͓ͬͯ͜͏ $ convert -background transparent \ -fill '#ff6060' -font Arial
-pointsize 128 label:LGTM lgtm.png ࢦఆαΠζͰ࡞ $ convert -size 400x200 -gravity center -background transparent \ -fill '#ff6060' -font Arial -pointsize 128 label:LGTM lgtm.png
߹ DPNQPTJUF original.jpgͷ্ʹlgtm.pngΛ߹ͯ͠ɺcompose-over.jpgͱͯ͠ग़ྗ $ convert original.jpg lgtm.png -gravity center \
-compose over -composite compose-over.jpg -geometryͰج४͔ΒҠಈ $ convert original.jpg lgtm.png -gravity center -geometry +150+50 \ -compose over -composite compose-over.jpg
None
ඳըϞʔυ CMFOENPEF -composeͰඳըϞʔυΛࢦఆ͢Δ ࢉ (multiply) $ convert original.jpg lgtm.png -gravity
center -geometry +150+50 \ -compose multiply -composite compose-multiply.jpg ΦʔόʔϨΠ (overlay) $ convert original.jpg lgtm.png -gravity center -geometry +150+50 \ -compose overlay -composite compose-overlay.jpg ݮࢉ (subtract) $ convert original.jpg lgtm.png -gravity center -geometry +150+50 \ -compose subtract -composite compose-subtract.jpg
None
None
None
ඳըϞʔυ CMFOENPEF wॏͶΒΕͨը૾ΛͲͷΑ͏ʹ߹͢Δ͔ΛࢦఆͰ͖Δ w IUUQJNBHFNBHJDLSVMF[KQBSDIJWFT w1IPUPTIPQͳͲͷը૾ฤूιϑτʹ͋Δͷͱಉ༷ w࣮ࡍͲΜͳܭࢉͰࢉग़͞ΕΔ͔ιʔεΛಡΊΘ͔Δʜ͕ɺײ֮Λ ͔ͭΉʹ(*.1ͷυΩϡϝϯτ͕Θ͔Γ͍͢ w IUUQTEPDTHJNQPSHKBHJNQDPODFQUTMBZFSNPEFTIUNM
wྫʣࢉɿ߹ը૾ͷ৭্ଆͷ৭ Լଆͷ৭
ը૾ՃαʔόΛ ࡞ͬͯΈΑ͏
-FOTɿ46;63*ͷը૾Ճαʔό w46;63*Ͱ͍ͬͯΔը૾ՃαʔόΛʮ-FOTʯͱݺΜͰ͍Δ wը૾ॲཧʹ*NBHF.BHJDLΛ༻ w5γϟπͷαϜωΠϧը૾ੜॲཧ͜͜ΒΜ w ࣾϦϙδτϦͷ63-ͷͨΊলུ
-(5.(FOFSBUPS ͯ͠ͳ͍ wͦͷ໊ʮ:04"406ʯ wIUUQTHJUIVCDPNTIJNPKVZPTBTPV w3&"%.&ΛಡΜͰΠϯετʔϧ͍ͯͩ͘͠͞ wॳճͷϏϧυͪΐͬͱ͕͔͔࣌ؒΓ·͢ʜʜ wϦϙδτϦԼʹదͳը૾Λஔ͍ͯɺ IUUQMPDBMIPTUJNBHFTJNBHFKQHʹΞΫηεͯ͠ΈΔ
(Pݴޠ w(PPHMF͕։ൃͨ͠ɺ͍ΖΜͳͷ͕ͳ͍ݴޠ ౖΒΕͦ͏ wΫϥε͕ͳ͍ɺΑͬͯܧঝͳ͍ wྫ֎͕ͳ͍ wδΣωϦΫε͕ͳ͍ wؔܕ༝དྷͷύϥμΠϜͳ͍ wෆมม0QUJPOBMɺNBQpMUFSͳͲͷίϨΫγϣϯૢ࡞
(Pݴޠ wݴޠ༷Λখ͘͢͞Δ͜ͱͰɺίϯύΠϧ͕ߴͰशಘ༰қ w͔ͳ͍ྖҬ͋Δ͕ɺదͨ͠ྖҬͰҖྗΛൃش͢Δ wόΠφϦ͕ੜ͞ΕΔͨΊɺ$-*πʔϧϛυϧΣΞʹศར w੩తܕͷԸܙΛड͚ͳ͕ΒɺܕਪͰܕΛ໌ࣔͤͣʹ։ൃͰ͖Δ wฒߦॲཧΛߦ͏ͨΊͷݴޠ༷ HPSPVUJOF ͕͋Γɺൺֱత؆୯ʹฒ ߦϓϩάϥϛϯά͕Ͱ͖Δ
දతͳιϑτΣΞ wίϚϯυϥΠϯπʔϧ wHIRɺQUɺIVHPɺOZBIDMJ wϛυϧΣΞɾαʔό w%PDLFSɺDPOTVMɺ%SPOFɺ45/4 wൺֱతখ͞ͳ ϚΠΫϩαʔϏεࢦͳ "1*αʔό wϩϦϙοϓʂϚωʔδυΫϥυͷ"1*αʔό wը૾Ճɾ৴αʔϏε*NBHF'MVY
ίʔυΛಡΜͰΈΑ͏ wNBJOHP wΤϯτϦϙΠϯτɻϦΫΤετϧʔλʔ ίϯτϩʔϥʔ w4JOBUSBͳͲͷΑ͏ͳϚΠΫϩϑϨʔϜϫʔΫελΠϧ wDPOWFSUFSJNBHFHP wը૾ՃΛநԽͨ͠ύοέʔδɻ͜͜Ͱ*NBHF.BHJDLΛར༻
ίʔυΛ͍ͬͯ͡ΈΑ͏ wυΩϡϝϯτΛಡΈͳ͕Β wJNBHJDLɿDPOWFSUFSJNBHFHPͰར༻ wIUUQTHPEPDPSHHPQLHJOHPHSBQIJDTJNBHJDLWJNBHJDL wHJOɿNBJOHPͰར༻ wIUUQTHPEPDPSHHJUIVCDPNHJOHPOJDHJO
·ͱΊ w46;63*Ͱը૾ॲཧ͕Ͳ͏ΘΕ͍ͯΔ͔Λͬͨ w*NBHF.BHJDLΛͬͨ؆୯ͳը૾ՃΛͬͯΈͨ wը૾ՃαʔόΛ͍ͬͯ͡Έͨ w(Pݴޠʹ৮ΕͯΈͨ
·ͱΊ wΰʔϧୡͰ͖·͔ͨ͠ʁ w*NBHF.BHJDLΛ༻ͨ͠ը૾ՃΛͬͯΈͯɺ wը૾ॲཧͨͷͦ͠͏ʂͬͯͳΔ͜ͱ
͜ΕͰ܅ -(5.ը૾࡞Γ์ͩʂ