グラビアと自由な情報共有についてまじめな話

opinion, tech

最近ツイッターで#グラドル自画撮り部というハッシュタグが話題になっています。グラビアアイドルたちが自画撮りをどんどんツイッターで公開していくという夢の様な企画。

部を立ち上げたのは、写メをよく公開することで知られていた倉持由香さん

最近発売された写真集がAmazonランキングで#1になるほどの人気ですが、その人気の理由の一つとしてツイッターの使い方も大きく働いていると思います。

これぞインターネットを有効活用した、自由な情報共有の理想の形なのでは?

グラビア業界を始め、音楽業界や映画業界はネットを通してコンテンツが無料で拡散してしまう現状に苦戦しています。そこで大半の偉い人の判断は、拡散を止めようと法律を固めようとしたり、一人あたりの売上を上げるために価格を高く設定する、などの反応になっています。

しかし今回の#グラドル自画撮り部はその考え方の逆で、興味を持ってくれている人を増やすための活動。以前は雑誌や写真集を本屋で購入することが普通でしたが、最近ではネットで楽に手に入るものにしか興味を持たないという傾向が進んでいます。消費者が求めているコンテンツの形がシフトしている中、それに合わせた新しいコンテンツを提供することができるのかが勝負になってきそうです。

音楽業界でも似たような動きが見られます。アメリカのアーティストMobyは11枚目のアルバム「Innocents」をBitTorrentで無料配信するというぶっ飛んだ企画を進行しました。その結果、Innocentsは2013で一番シェアされたトレントとなり、合計で890万回ダウンロードされるというすさまじい結果となりました。話題になり、音楽を聞いてくれる人が増えるとファンも増えて売上にもつながる、ととても前向きでオープンな発想です。

今後に合わせてこのような変化は必要になっていくと思いますし、新しい動きがしにくいエンターテイメント業界の中でその先行者になっている方々を応援していきたいと思います。

Rake Task to Backup MySQL to Amazon S3

programming, ruby, tech

A simple rake task to dump the contents of a MySQL database and save it to an Amazon S3 bucket. Use together with whenever to automate it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
namespace :backup do

  task :nightly do
    timestamp = Time.now.strftime("%Y-%m-%d_%H-%M-%S")
    backup_file = "tmp/backups/#{timestamp}_dump.sql.gz"
    `mkdir -p tmp/backups`
    `mysqldump -u root {DATABASE_NAME} | gzip -c > #{backup_file}`

    send_to_s3 backup_file
  end

  def send_to_s3(file_path)
    bucket = "{BUCKET_NAME}"
    file_name = File.basename(file_path)
    AWS::S3::DEFAULT_HOST.replace "s3-us-west-2.amazonaws.com"

    AWS::S3::Base.establish_connection!(
      :access_key_id => '{KEY}',
      :secret_access_key => '{SECRET}')

    AWS::S3::S3Object.store(
      "backups/#{file_name}",
      File.open("#{file_path}"),
      bucket)
  end

end

Pokemon Fusion: Behind the Scenes

programming, ruby, tech

I’ve been getting a few questions about the script used to generate the Pokemon Fusion sprites, so I thought I would write a quick blog post to describe the process.

The inspiration of the website was the idea that it should be possible to automate the process of combining pokemon sprites, and each image is automatically generated by a computer script. Some of the results are less impressive than others, but I think that it adds to the fun and makes it that much more satisfying when you come across ones that work really well.

Preparation

There is a small amount of manual work that goes into adding a new pokemon to the website. It comes down to collecting some basic information about the head’s size and position, as well as the colors that are used.

First, I download the new pokemon’s sprite from Bulbapedia, and manually cut out the head and save it as a new image. The body is also saved separately, and these become the basic parts that are combined with those from other pokemon to create the fusions.

Separating the head from the body

To collect and save each pokemon’s data, I made a simple admin page.

Admin page

  • Inputting the name as a prefix + suffix allows me to combine them to name the results.
  • Face size is taken automatically from the size of the image, and Head size is used to adjust for unusually-shaped faces. In this example, I wanted the lower jaw and whiskers to hang below the main head location so I set the head size to be smaller, matching the colored-out area of the body.
    • To make setting the face’s size and position easier, there’s a little javascript that lets me click on a point on the image to output the coordinates automatically.
  • The basic idea behind the colors is that each sprite will have at most 3 different colors, with at most 5 shades of each color. The 3rd shade of each color is set to be the primary color, with the 2 shades on either side defining highlights and shadows.
    • I made a little script here too, that lets me click on a point in the image to automatically output the hex value of that pixel.

Color picker widget

After all of the data is saved, I run my fusion script to combine the new pokemon with all of the existing pokemon. At this point, by just adding a few data points for a new pokemon I can generate over 100 new fusions nearly instantly.

The script

The image processing is done with ImageMagick, and I use the RMagick gem to work with it in Ruby. I plan to open source the code after I clean things up more, but here are the most important parts:

Swap the colors to match the new face

1
body1 = body1.opaque_channel("##{pk1['primary'][i]}","##{pk2['primary'][i]}")

This code looks at the image body1 for every pixel of the given color pk1['primary'][i] and changes it to the second given color pk2['primary'][i]. We will then loop for each of the 5 shades of each of the 3 colors.

Resize the face to match its new body

1
2
3
4
5
6
7
headratiox1 = 1.0 * pk2['headsize'][0] / pk1['headsize'][0]
headratioy1 = 1.0 * pk2['headsize'][1] / pk1['headsize'][1]

newx = pk1['facesize'][0] * headratiox1
newy = pk1['facesize'][1] * headratioy1

face1 = face1.resize(newx, newy)

First, we compare the heads of the two pokemon and see much bigger/smaller the head we’re working with is. Once we have this ratio, we resize the face image by this ratio.

Since we made defined the head to be smaller than the face (to support irregular faces with beaks, tongues, or whiskers that spill over the head area), this makes sure that the face image isn’t shrunken down too much.

Put the head in the right place

1
body1 = body1.composite(face2, face2x, face2y, Magick::OverCompositeOp)

composite is the function that overlays an image over another image, and here we are placing the image face2 on top of the image body1 at the coordinates (face2x, face2y).

That’s it!

After looping over each existing pokemon the script generates all new combinations using the new pokemon, and I just upload the new images and update the site to show the new combinations.

The results

If you have any other questions, feel free to reach out over email or twitter.

Geoguessr

game

See a Google Street View at a random point in the world, guess where it is on a map.

Save to Pocket - OSX Service

mac, programming, tool

Here’s a quick Mac OSX service that will allow you to save any link to Pocket by right-clicking it. It will work from within basically any app that lets you right-click text. Prerequisite is that you have the Pocket OSX app installed.

Download the script here

After downloading, unzip and place the file in ~/Library/Services (or create the folder first if it doesn’t exist already)

After doing so, you should be able to simply highlight a link and right-click it to see the “Save to Pocket” option. (You might find it under a “Services” category)

Save to Pocket

Backgammon 3rd Anniversary

life, music, photo

4/21はいつもお世話になっているBackgammonの3周年パーティー。楽しいライブの演奏が盛りだくさんでした。