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
ImageUpload Casual
Search
terut
October 05, 2012
Programming
3
750
ImageUpload Casual
ImageUploadをカジュアルに考えてみた
terut
October 05, 2012
Tweet
Share
More Decks by terut
See All by terut
try making
terut
1
1.1k
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
420
大規模アプリのDIフレームワーク刷新戦略 ~過去最大規模の並行開発を止めずにアプリ全体に導入するまで~
mot_techtalk
1
460
CSC509 Lecture 04
javiergs
PRO
0
300
AI Coding Meetup #3 - 導入セッション / ai-coding-meetup-3
izumin5210
0
3.3k
チームの境界をブチ抜いていけ
tokai235
0
180
Things You Thought You Didn’t Need To Care About That Have a Big Impact On Your Job
hollycummins
0
230
CSC305 Lecture 05
javiergs
PRO
0
220
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
0
300
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
390
はじめてのDSPy - 言語モデルを『プロンプト』ではなく『プログラミング』するための仕組み
masahiro_nishimi
2
560
Devvox Belgium - Agentic AI Patterns
kdubois
1
120
NixOS + Kubernetesで構築する自宅サーバーのすべて
ichi_h3
0
990
Featured
See All Featured
Being A Developer After 40
akosma
91
590k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.8k
Documentation Writing (for coders)
carmenintech
75
5.1k
RailsConf 2023
tenderlove
30
1.2k
A Tale of Four Properties
chriscoyier
161
23k
Site-Speed That Sticks
csswizardry
13
910
Practical Orchestrator
shlominoach
190
11k
What's in a price? How to price your products and services
michaelherold
246
12k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.5k
How GitHub (no longer) Works
holman
315
140k
Transcript
ImageUpload Casual Togo@terut
ImageUpload Casualͱʁ ਂ͘ઙ͘ɺ͘ڱ͘ImageUploadʹ͍ͭͯߟ ͑ͯΈΑ͏ͱ͍͏ࢼΈ MySQL CasualͷύΫϦ GachualͰͳ͍
ImageUpload ImageMagick convert mogrify identfy ImageUploadͷΩϞ convertͱmogrifyͷҧ͍ΛѲ͢Δ content-typeͱ͔͋Δ
pjpeg?? problem IEͱ͔͍͏HTMLΛrender͢ΔπʔϧΛͬͨ ߹ʹ͘ΔΒ͍͠content-type ϒϥβҎ֎͔Βpost͢Δͱ… pjpegͱ͔x-pngͱ͔͋Δ redirect chrome unless Hoge.isBrowser?
࣮Α
͕ແ͔͠ΕΜ͠… x-pngಉ༷ʹͳ͍
Casual note 1 pjpeg, x-pngͳͲͯ͢ڧ੍తʹjpeg, png objective-cͩͱpjpegΛૉʹදࣔͰ͖ͳ͔ͬ ͨͷͰ ϒϥβͳΒͳ͘දࣔͰ͖Δ
Uma.jpg Problem a.k.a അը૾ 500KBʢ600x◦◦ʣ ࠓHIKARI࣌ͩ͠ɺͦΜͳͷ༨༟ͬ͠ΐͱ ͔ݴͬͪΌ͏ͭ֯ͰখࢦͿ͚ͭΖ ΫϥΠΞϯτʹcache͠ΖͬͯݴͬͪΌ͏ͭ ਖ਼͍͠Ͱ͍͢͢·ͤΜͰͨ͠
ܰ͞ਖ਼ٛ εϚϗΞϓϦ3Gɺը૾ݟͨΩϨΠͰܰ ͍΄͏͕ମײવ͍ ͍ܰͱۭؒޮΑ͍ʢը૾Λmemory cacheʣ ྫ͑ face ͳΜͱ͔ - 70ʙ100KBલޙ
ʢ600x◦◦ʣ path - 200KBલޙ (918x1632ʣ
Casual note 2 imageΛܰྔԽ qualityΛ80ʙ85 mogrify -quality 80 hoge.jpg default75ͬΆ͍͚ͲɺlibraryʹΑͬͯ
100ͱ͔ͬͪΌͬͯΔͷ͋Δ ϑΝΠϧαΠζʹେ͖ؔ͘ΘΔΦϓγϣϯ
Exif Exif - Exchangeable image file format Πάδϑ͘͠Τάδϑ Χϝϥͷػछ ࡱӨ࣌ͷ݅
ϑϥογϡͷ༗ແ GPSͱ͔৭ʑ
Exif ͱʙ
Exifʹࢥ͍ग़͕͋Δ ͕͓ͩલͷࢥ͍ग़ʹΈΜͳͦΜͳڵຯͳ͍ ͠Λ੧·ͤ GPSͳͲෆཁͳใͩͬͨΓɺಛఆ͞ΕΔ͜ ͱेՄೳੑͱͯ͋͠Δ ϝλσʔλͩ͠ΕϑΝΠϧαΠζ͕ݮΔ
GPS… LocateϘλϯΛԡͨͥ͠…
Ͱ͢·͞Εͳ͍͜ͱ͕ى͖Δ͔…
Casual note 3 ෆཁͳใΛΔ ݸਓใతͳҙຯͰ mogrify -strip hoge.jpg
rotate problem Uploadͨ͠Βը૾͕ԣ͖ ͜Ε߄ͯΔ͠ Ή͠Ζ߄ͯΖ
Orientation ը૾͖ͷใΛ࣋ͬͯΔ ͦͷ··convert͢ΔͱSendo͕͍Α͏͕߄ͯΔ
Casual note 4 OrientationΛߟྀͯ͠convert mogrify -auto-orient hoge.jpg ͖ͬ͞ͷ-stripͰExifͷϝλσʔλΛΔ orientationফ͑ΔͷͰ·͞Εͳͯ͘͢Ή
Casual note 5 image dimention mogrify -resize 600x> hoge.jpg 600xൺͷॎ
ྫ͑originalΛresize 1200x>ͱͯ͠อଘ dimensionม͑ͳͯ͘sizeݮΒͦ͏ͥ…
QuantumDepth Q8 - QuantumDepth 8 version RGB֤ཁૉͷղೳ͕8bit, 16bitʢը૾ॲཧͷ ਫ਼͕ߴ͍͔Ͳ͏͔తͳײͬ͡Ά͍ʣ Q8Q16ʹൺͯϝϞϦ༻ྔɺ
CPU༻ྔ30%ఔগͳ͍ͱ͔
Casual note 6 Q8Λ͏ HomebrewͰೖΔͷQ16 ίϯύΠϧ࣌ʹ--with-quantum-depth=8Λͭ ͚Δ͔ɺconvertͰ-depth 8Λ͚ͭΔ mogrify -depth
8 hoge.jpg iPhonedepth 8ʹͳͬͯΔΑ͏ͳ ݕূͯ͠ͳ͍ʢͩͬͯΧδϡΞϧ͔ͩΒͶʂ
convert slow problem ຊ൪ʹdeploy͔ͯ͠Δ convert ͞ AWSͷ͍҆ͭͦΕͳΓεϖοΫ youͷmacSSDͰquadͰmemory8Gͳ͜ͱΛ ͓Ε͔
None
speed, speed, speed jpegͳΒdefineΦϓγϣϯʹΑΓ10ഒߴԽ http:/ /blog.mirakui.com/entry/ 20110123/1295795409 ࠓͲ͖ͷPanda͞Μ ͍͢͝ ৄ͍͠આ໌ϦϯΫͰʢͩͬͯΧδϡry
Env MacBook Air 13inch Core i5 1.7GHz memory 4G SSD
Image 4032x3024 5.1MB The Greatest Image (Special Thanks Hym)
Command
Bench
Resized Image 600x450 59KB small, but The Greatest Image
Compare Resized vs Resized with define
Casual note 7 -define jpeg:sizeͰߴԽ ྫ͑ɺiOSΞϓϦ͔ΒͷimageΛͯ͢jpeg ʹ͢Δ ը૾ฤू͠ͳ͍͠ɺҰཡը૾ͱ͔jpeg mogrify -define
jpeg:size=”600x>” ...
Casual Planʢޙʹ mogrify -unsharp ͰΩϨΠ mogrify -color [number] Ͱը࣭ͱαΠζͷό ϥϯε
OpenMpͷon/offʢ͜ͷล@hattorix0ͷ΄͏ ͕ৄͦ͠͏ͳͷͰڭ͑Ζ͍ͩ͘͞ʣ QuantumDepth libjpeg-turbo!!!
RubyͰ͏ ྫ͑CarrierWaveͱMimiMagick MiniMagickmogrifyΛୟ͘ͷͰࠓ·ͰͷΦϓ γϣϯ͕͑Δ
content-type
oreore process method CarrierWaveʹ͋Δprocess :resize_to_limitͱ ͔manipulate!Λ͍ɺΑ͘͏ॲཧͱͯ͠ resize_to_limit methodΛՃͯ͠Δ͚ͩ Α͔Ζ͏ɺͳΒoreoreͩ
Casual note matome
keypoint manipulate! https:/ /github.com/jnicklas/carrierwave/blob/ master/lib/carrierwave/processing/ mini_magick.rb mogrify command https:/ /github.com/probablycorey/
mini_magick/blob/master/lib/mini_magick.rb formatͰcontent-type·Ͱม͠ͳ͍
PHPͰ͏ ΒΜ optionΛbuildͯ͠mogrifyୟ͘Α͏ʹ͢Ε͍ ͍͚ͩ library͕ͳ͍ʁ php-mini-magick͞Μ… ࣗͰ࡞Ε͍͍Μ͡Όͳ͍Ͱ͔͢Ͷʂʂʂ
ه convertը૾͕ͿͬյΕͯͨΓɺը૾͡Όͳ ͚ΕΤϥʔ͘ libjpeg-turboݕূͨ݁͠ՌɺͪΌΜͱૣ͘ ͳͬͨʢΧδϡry pixiv thumbnailͷεϥΠυͱ͔ݟͨΒΑ͍