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
720
ImageUpload Casual
ImageUploadをカジュアルに考えてみた
terut
October 05, 2012
Tweet
Share
More Decks by terut
See All by terut
try making
terut
1
1k
Other Decks in Programming
See All in Programming
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
170
入門 AWS Amplify Gen2 / Introduction to AWS Amplify Gen2
genkiogasawara
1
330
Zero Waste, Radical Magic, and Italian Graft – Quarkus Efficiency Secrets
hollycummins
0
230
雑に思考を整理する技術と効能
konifar
58
29k
VS Code をプロダクトにどう取り込むか
onomax
1
350
Random\Randomizer クラスで日常のあれこれを解決しよう! / Random\Randomizer class solves familiar trouble
cocoeyes02
0
210
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
720
TYPO3 v13 – The road to LTS: What's new and new APIs
luisasofie_xoxo
0
190
Milestoner
bkuhlmann
1
410
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
120
#phpcon_odawara オープン・クローズドなテストフィクスチャを求めて / open closed test fixtures
77web
3
230
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
8
4k
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
31
46k
Designing Experiences People Love
moore
136
23k
Learning to Love Humans: Emotional Interface Design
aarron
267
39k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
It's Worth the Effort
3n
180
27k
Navigating Team Friction
lara
178
13k
Gamification - CAS2011
davidbonilla
76
4.6k
Design by the Numbers
sachag
274
18k
Building Adaptive Systems
keathley
31
1.9k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
14
1.5k
Agile that works and the tools we love
rasmusluckow
325
20k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
60
14k
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ͷεϥΠυͱ͔ݟͨΒΑ͍