產生模糊縮圖的 BlurHash

先從一張圖片算出大約 20~30 bytes 的字串,就可以在 API response 時快速產生出一個很模糊但是有有代表性的縮圖 (或是在 HTML 裡面放,用 javascript 產生):「BlurHash」。

從官方給的範例比較快理解:

以及:

另外也提供了展現在 app 上的效果:

有支援一些程式語言,不過看起來行動平台上的支援都是比較新的語言 (Swift & Kotlin),如果不是用這些語言而想用 BlurHash 的話就得自己整了...

另外在 Hacker News 上有翻到先前的討論:「BlurHash: Algorithm to generate compact representation of an image placeholder」,開頭就看到其他軟體的作法:

For comparison, Instagram sends ~200 byte base64 thumbnails in its API responses. It's a low-res JPEG with a fixed header to save a bit more space. This is also used to blur sensitive images. You can get even better results with webp.

這個方法就避開另外再弄一包 library 進去,用現成的 library 就會動了...

用 OpenCV 與類神經網路放大圖片

在「Deep Learning based Super Resolution with OpenCV」這邊看到 OpenCV 支援這些類神經網路的演算法了,而且有預先訓練好的模型資料可以下載來用。

傳統放大的方法包括 bicubic 與 nearest neighbor,速度很快但是效果就普普通通,而 NN 類的方法的效果遠超過傳統方式,不過速度慢不少。

文章裡面有提到可以指定不同的 NN 模型:

The first parameter is the name of the model. You can choose between: “edsr”, “fsrcnn”, “lapsrn”, “espcn”. It is very important that this model is the correct one for the model you specified in ‘sr.readModel()’. See the Model section on the bottom of the page for the specifications of each model.

拿這些模型名字搜了一下資料,在「Super-resolution benchmarking」這邊可以看到比較,主要是在講 EDSR 很棒,然後 ESPCN 很快?

不過看起來可以直接拿來用在不少地方了...

Flickr 限縮免費帳號的容量

Flickr 在今年四月的時候放出消息被 SmugMug 收購後 (參考先前的文章「SmugMug 買下 Flickr」),過了半年總算是有新的動作了,跟 SmugMug 完全走使用者付費的想法類似,這次將免費帳號的容量大幅限縮,從本來的 1TB 空間變成 1000 張照片,在 2019/01/08 將會生效:「Why we’re changing Flickr free accounts」。

Beginning January 8, 2019, Free accounts will be limited to 1,000 photos and videos. If you need unlimited storage, you’ll need to upgrade to Flickr Pro.

現在點進去看 Flickr Pro 的費用是 USD$35/year。我在 2005 年以 USD$59.95/year 買過當時的 Flickr Pro... 特別有印象是因為剛好是宣佈被 Yahoo! 收購的前幾天買的訂閱,在被收購後 Flickr 宣佈降價,而先前買的人直接多一年。

參考當年的「http://www.flickr.com/help.gne」頁面):

We are currently offering an introductory Pro Account special -- Buy yourself (or a friend) an annual Pro Account for US$41.77 and save yourself around 30% from the anticipated annual price of $59.95. That's less than $3.50 a month!

不過現在好像也用不到這個平台了... 反正都公開的資料,也許資料拉一拉丟到其他地方吧,或是想看看要怎麼放。

SmugMug 買下 Flickr

SmugMug 買下 Flickr,這應該算是好消息 (吧):「Exclusive: Flickr bought by SmugMug, which vows to revitalize the photo service」。

雙方的新聞稿是:「SmugMug acquires Flickr: Two passionate communities together at last.」與「Together is where photographers belong!」。

時代的眼淚啊... 還在交大的時候買了 Pro,後來被併進 Y! 後沒續約了。丟著直到 Instagram 可以同步上去時又有更新,然後 Instagram 停止分享到 Flickr 的功能後又改找 IFTTT 同步。

而本來做 Flickr 的那群人後來跑去做 Slack... (包括 Stewart ButterfieldCal Henderson XD)

來看看後續會有什麼改變... 第一波應該是帳號系統的轉移?然後再來是 pricing model 的改變?

Seam Carving (接縫裁剪)

看到有人實做 Seam Carving (接縫裁剪) 了,用 Golang 寫的,放在 GitHubesimov/caire 這邊,副標題「Content aware image resize library」。實做了「Seam Carving for Content-Aware Image Resizing」這篇論文。

Seam Carving 指的是知道內容的 resize,像是把上面這張變成下面這張:

或是變大:

馬上可以想到的應用是需要保留資訊內容,但又想要大量提供資訊的地方,像是 Nuzzle 的縮圖 (或是以前的 Zite),或是網路新聞媒體的首頁所用的縮圖。不知道還有沒有其他地方可以用...

Facebook 的智障防範措施...

Facebook 新的防範報復性照片計畫不少媒體都有報導了,我拿 Bruce Schneier 這篇來引用好了:「Facebook Fingerprinting Photos to Prevent Revenge Porn」。

重點是:

According to a Facebook spokesperson, Facebook workers will have to review full, uncensored versions of nude images first, volunteered by the user, to determine if malicious posts by other users qualify as revenge porn.

智障... 結果裸照從這些管道先傳出去?

AWS 推出新的 Cost Explorer API,不過 API 不是重點啦...

AWS 的「New – Interactive AWS Cost Explorer API」這篇文章在一開頭就提到了 Cost Explorer API 的情況,所以他們要推出新的 API 改進:

We launched the AWS Cost Explorer a couple of years ago in order to allow you to track, allocate, and manage your AWS costs. The response to that launch, and to additions that we have made since then, has been very positive. However our customers are, as Jeff Bezos has said, “beautifully, wonderfully, dissatisfied.”

不過讓我笑出來的是選圖啊... 大概是 Jeff Barr 夠硬的關係,直接選了這張:

我喜歡這張 XD (尤其配合著出現在官方 blog 上的時候)

Google Chrome 支援 APNG 了...

翻資料的時候才發現 Google Chrome 從 59 版 (今年六月進 stable channel) 就支援 APNG 了,這樣所有主流瀏覽器只剩下微軟家的 IE 與 Edge 還沒支援了:

找了一下當時的新聞:「Chrome 59 will fully support animated PNGs」,以及對應的 ticket:「Request for enhancement: APNG (animated PNG)」。

APNG 相較於 GIF 多了透明的設計 (GIF 需要拿一個顏色來當作透明),以及更多的色彩,但對於瀏覽器的支援一直都不完整:

The GIF file format has better application and browser support than APNG, but it is limited to 256 colors per frame and supports only index transparency, by mapping one of the palette colors to transparent.

現在這樣讓 GIF 退休的日子又前進了一大步...

imgproxy:自動處理圖片的工具

看到「imgproxy: Resize your images instantly and securely」這篇文章,介紹「DarthSim/imgproxy」這個專案,想起很久以前的同事在 PIXNET 弄的 *.pimg.tw 系列服務...

imgproxy 可以 resizing,也可以 croping,然後也支援 signature token 機制,感覺是每個大一點的站台都會自己刻一次的服務 XD

整個專案以 Golang 為主,效能應該是不錯... 不過一般前面還是會放 cache 機制 (像是 CDN 之類的服務),而不會把 loading 直接打進來,避免同樣的圖片一直重複計算。

Google 推出的 PhotoScan,利用多張照片去除反光

Google 推出的 PhotoScan (AndroidiOS) 可以利用多次不同角度的拍攝來消除反光:「PhotoScan: Taking Glare-Free Pictures of Pictures」。

把這五張照片轉成一張處理過的照片: