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
740
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
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
100
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
Outline View in SwiftUI
1024jp
1
330
役立つログに取り組もう
irof
28
9.6k
Ethereum_.pdf
nekomatu
0
460
Jakarta EE meets AI
ivargrimstad
0
650
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
flutterkaigi_2024.pdf
kyoheig3
0
150
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Navigating Team Friction
lara
183
14k
Adopting Sorbet at Scale
ufuk
73
9.1k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
RailsConf 2023
tenderlove
29
900
Automating Front-end Workflow
addyosmani
1366
200k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Facilitating Awesome Meetings
lara
50
6.1k
KATA
mclloyd
29
14k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
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ͷεϥΠυͱ͔ݟͨΒΑ͍