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
GitHubとGitLabとAWS CodePipelineでCI/CDを組み比べてみた
satoshi256kbyte
4
250
時間軸から考えるTerraformを使う理由と留意点
fufuhu
16
4.8k
もうちょっといいRubyプロファイラを作りたい (2025)
osyoyu
1
460
Ruby×iOSアプリ開発 ~共に歩んだエコシステムの物語~
temoki
0
350
Rancher と Terraform
fufuhu
2
550
私の後悔をAWS DMSで解決した話
hiramax
4
210
rage against annotate_predecessor
junk0612
0
170
奥深くて厄介な「改行」と仲良くなる20分
oguemon
1
570
さようなら Date。 ようこそTemporal! 3年間先行利用して得られた知見の共有
8beeeaaat
3
1.5k
Android 16 × Jetpack Composeで縦書きテキストエディタを作ろう / Vertical Text Editor with Compose on Android 16
cc4966
2
270
The Past, Present, and Future of Enterprise Java with ASF in the Middle
ivargrimstad
0
180
Tool Catalog Agent for Bedrock AgentCore Gateway
licux
7
2.5k
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
96
6.2k
A designer walks into a library…
pauljervisheath
207
24k
Code Reviewing Like a Champion
maltzj
525
40k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
For a Future-Friendly Web
brad_frost
180
9.9k
A Tale of Four Properties
chriscoyier
160
23k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
Code Review Best Practice
trishagee
71
19k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.6k
Optimising Largest Contentful Paint
csswizardry
37
3.4k
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ͷεϥΠυͱ͔ݟͨΒΑ͍