#困ったこと
CloudinaryのテキストオーバーレイがGoogleのウェブフォントをサポートしていると書いてあったのですが、日本語フォントを指定してみたのですが、ことごとく400エラーが返ってきてしまいました。Googleフォントのうち、どのフォントが使えるのか、全部のフォントを総当たりして確認してみました。
2018年12月8日時点で904フォント登録されてますが、日本語が使えるのは12フォントだけです。
https://fonts.google.com/?subset=japanese
- Kosugi
- [Kosugi Maru](https://fonts.google.com/specimen/Kosugi Maru)
- [M PLUS 1p](https://fonts.google.com/specimen/M PLUS 1p)
- [M PLUS Rounded 1c](https://fonts.google.com/specimen/M PLUS Rounded 1c)
- [Noto Sans JP](https://fonts.google.com/specimen/Noto Sans JP)
- [Noto Sans SC](https://fonts.google.com/specimen/Noto Sans SC)
- [Noto Sans TC](https://fonts.google.com/specimen/Noto Sans TC)
- [Noto Serif JP](https://fonts.google.com/specimen/Noto Serif JP)
- [Noto Serif SC](https://fonts.google.com/specimen/Noto Serif SC)
- [Noto Serif TC](https://fonts.google.com/specimen/Noto Serif TC)
- [Sawarabi Gothic](https://fonts.google.com/specimen/Sawarabi Gothic)
- [Sawarabi Mincho](https://fonts.google.com/specimen/Sawarabi Mincho)
2020年1月4日時点で977フォント登録されてますが、日本語が使えるのは8フォントだけです。
https://fonts.google.com/?subset=japanese
- Kosugi
- [Kosugi Maru](https://fonts.google.com/specimen/Kosugi Maru)
- [M PLUS 1p](https://fonts.google.com/specimen/M PLUS 1p)
- [M PLUS Rounded 1c](https://fonts.google.com/specimen/M PLUS Rounded 1c)
- [Noto Sans JP](https://fonts.google.com/specimen/Noto Sans JP)
- [Noto Serif JP](https://fonts.google.com/specimen/Noto Serif JP)
- [Sawarabi Gothic](https://fonts.google.com/specimen/Sawarabi Gothic)
- [Sawarabi Mincho](https://fonts.google.com/specimen/Sawarabi Mincho)
結果から言うと、CloudinaryのTextオーバーレイで使えるフォントはSawarabi Gothic
とSawarabi Mincho
が使えました。他はNGでした。
#使ったもの
PHP
Cloudinary
google fonts (https://fonts.google.com/)
developer API (https://developers.google.com/fonts/docs/developer_api)
#やったこと
- google APIでfont familyの一覧を取り出し
- CloudinaryのURLを組み立ててリクエストを投げて
- HTTPのステータスコードを取り出す
##コード
cloud_nameとlimitは適当に変えてください。
<?php
$google_api_token = 'xxx-yyy';
$font_api_url = 'https://www.googleapis.com/webfonts/v1/webfonts?key=' . $google_api_token;
$cloud_name ='demo';
$limit = 100;
$font_json = file_get_contents($font_api_url);
$font_list = json_decode($font_json, true);
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
$result =[
'200'=>[],'400'=>[],
];
foreach($font_list['items']??[] as $n=>$font){
$font_family = $font['family'];
echo ($n+1).'/'.count($font_list['items']) . " " . $font_family . PHP_EOL;
$cloudinary_url = "https://res.cloudinary.com/$cloud_name/l_text:".
rawurlencode($font_family).
'_40_center:ABC,co_rgb:ffffff/sample.jpg';
echo $cloudinary_url . PHP_EOL;
curl_setopt($curl, CURLOPT_URL, $cloudinary_url);
$response = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
echo $code . ' ' . $font_family . PHP_EOL;
// echo $header . PHP_EOL;
if( preg_match('/x-cld-error: (.*)/i', $header, $_)){
echo $_[1] . PHP_EOL;
}
$result[$code][]=$font_family;
if( $n+1 >= $limit ){
break;
}
echo PHP_EOL;
}
var_dump($result['200']);
var_dump($result['400']);
echo "end of batch";
##結果
907フォント中、71フォントが使えませんでした。NotoとかM+が使えないのが残念です。
- [Bai Jamjuree](https://fonts.google.com/specimen/Bai Jamjuree)
- [Black And White Picture](https://fonts.google.com/specimen/Black And White Picture)
- [Black Han Sans](https://fonts.google.com/specimen/Black Han Sans)
- [Cantora One](https://fonts.google.com/specimen/Cantora One)
- [Chakra Petch](https://fonts.google.com/specimen/Chakra Petch)
- Charmonman
- [Cute Font](https://fonts.google.com/specimen/Cute Font)
- [David Libre](https://fonts.google.com/specimen/David Libre)
- [Do Hyeon](https://fonts.google.com/specimen/Do Hyeon)
- Dokdo
- [East Sea Dokdo](https://fonts.google.com/specimen/East Sea Dokdo)
- Fahkwang
- [Fjord One](https://fonts.google.com/specimen/Fjord One)
- Gaegu
- [Gamja Flower](https://fonts.google.com/specimen/Gamja Flower)
- [Gothic A1](https://fonts.google.com/specimen/Gothic A1)
- Gugi
- [Hammersmith One](https://fonts.google.com/specimen/Hammersmith One)
- [Headland One](https://fonts.google.com/specimen/Headland One)
- [Hi Melody](https://fonts.google.com/specimen/Hi Melody)
- [IBM Plex Mono](https://fonts.google.com/specimen/IBM Plex Mono)
- [IBM Plex Sans](https://fonts.google.com/specimen/IBM Plex Sans)
- [IBM Plex Sans Condensed](https://fonts.google.com/specimen/IBM Plex Sans Condensed)
- [IBM Plex Serif](https://fonts.google.com/specimen/IBM Plex Serif)
- Jua
- K2D
- Kantumruy
- [Kirang Haerang](https://fonts.google.com/specimen/Kirang Haerang)
- KoHo
- Kodchasan
- Kosugi
- [Kosugi Maru](https://fonts.google.com/specimen/Kosugi Maru)
- Krub
- [Kumar One Outline](https://fonts.google.com/specimen/Kumar One Outline)
- [M PLUS 1p](https://fonts.google.com/specimen/M PLUS 1p)
- [M PLUS Rounded 1c](https://fonts.google.com/specimen/M PLUS Rounded 1c)
- Mali
- [Markazi Text](https://fonts.google.com/specimen/Markazi Text)
- Moulpali
- [Nanum Gothic](https://fonts.google.com/specimen/Nanum Gothic)
- [Nanum Gothic Coding](https://fonts.google.com/specimen/Nanum Gothic Coding)
- [Nanum Myeongjo](https://fonts.google.com/specimen/Nanum Myeongjo)
- [Nanum Pen Script](https://fonts.google.com/specimen/Nanum Pen Script)
- Niramit
- Nokora
- Notable
- [Noto Sans JP](https://fonts.google.com/specimen/Noto Sans JP)
- [Noto Sans KR](https://fonts.google.com/specimen/Noto Sans KR)
- [Noto Sans SC](https://fonts.google.com/specimen/Noto Sans SC)
- [Noto Sans TC](https://fonts.google.com/specimen/Noto Sans TC)
- [Noto Serif JP](https://fonts.google.com/specimen/Noto Serif JP)
- [Noto Serif KR](https://fonts.google.com/specimen/Noto Serif KR)
- [Noto Serif SC](https://fonts.google.com/specimen/Noto Serif SC)
- [Noto Serif TC](https://fonts.google.com/specimen/Noto Serif TC)
- [Odor Mean Chey](https://fonts.google.com/specimen/Odor Mean Chey)
- [Poor Story](https://fonts.google.com/specimen/Poor Story)
- Preahvihear
- [Raleway Dots](https://fonts.google.com/specimen/Raleway Dots)
- [Saira Extra Condensed](https://fonts.google.com/specimen/Saira Extra Condensed)
- [Saira Semi Condensed](https://fonts.google.com/specimen/Saira Semi Condensed)
- [Sirin Stencil](https://fonts.google.com/specimen/Sirin Stencil)
- [Song Myung](https://fonts.google.com/specimen/Song Myung)
- Srisakdi
- Stylish
- [Sue Ellen Francisco](https://fonts.google.com/specimen/Sue Ellen Francisco)
- Sunflower
- [Supermercado One](https://fonts.google.com/specimen/Supermercado One)
- Suwannaphum
- Tajawal
- Vidaloka
- [Yeon Sung](https://fonts.google.com/specimen/Yeon Sung)
2020年1月4日時点で141フォントがNGです。
#参考資料
What is the list of supported fonts for text overlay transformation?
https://support.cloudinary.com/hc/en-us/articles/203352832