mediaãã©ã°ã¤ã³å¿ç¨(8) Versionãã¡ã¤ã«ã®mimeTypeãä»»æã§åºå
Mediaãã©ã°ã¤ã³ã®ãVersionãã¡ã¤ã«æ©è½ãã§åºåããã縮å°ç»åã®ããã¡ã¤ã«ã¿ã¤ããä»»æã«é¸ã¹ãæ¹ä¿®ã追å ãã¾ããã
注ï¼ãã®è¨äºã¯ãViewで呼び出し時にVersionファイルを作成する æ¹ä¿®æ¸ã¿ã®ã½ã¼ã¹ããã¼ã¹ã«è¨è¼ãã¦ãã¾ãã
mimeTypeã®è¨å®
Versionãã¡ã¤ã«ã®mimeTypeãå¤æ´ããã«ã¯ãconvert設定ãé©å®å¤æ´ãã¾ãã
ä¾
Configure::write('Media.filter.image', array( - 'xxs' => array('convert' => 'image/png', 'fitCrop' => array(16, 16)), + 'xxs' => array('convert' => 'image/jpeg', 'fitCrop' => array(16, 16)),
core.phpãbootstra.phpã§è¨å®ããã¨ãå ¨ã¦ã®ç»åã®xxsãµã¤ãºç¸®å°ãã¡ã¤ã«ã jpg åºå®ã«ãªãã¾ãã
mimtTypeé©å®æå®ãããå ´åã¯ãä¾ãã°ä»¥ä¸ã®æ§ã«æ¹ä¿®ãã¾ã(å¼ç¨ã½ã¼ã¹ã®å§ç´°ã¯ こちら åç §)
- Versionãã¡ã¤ã«åºåæã$options['mimeType']ã®æå®ãããå ´åãconvertè¨å®ã$options['mimeType']ã§ä¸æ¸ãã
app/plugins/media/libs/upfile.php(Versionãã¡ã¤ã«åºåã©ã¤ãã©ãª)
/* Versionãã¡ã¤ã«ã®åå¥ä½æ */ function make_version($path, $orig_filepath, $options=array()) { ï¼ä¸ç¥ï¼ // Confirgureã®è¨å® $name = Medium::name($orig_filepath); $filters = Configure::read('Media.filter.'. strtolower($name)); if (!isset($filters[$dir])) { return false; } - Configure::write('Media.filter.'. strtolower($name), array($dir => $filters[$dir])); + $filter[$dir] = $filters[$dir]; + // mimeTypeè¨å® + if (isset($options['mime_type']) && !empty($options['mime_type'])) { + $filter[$dir]['convert'] = $options['mime_type']; + } + Configure::write('Media.filter.'. strtolower($name), array($dir => $filter[$dir])); // Versionãã¡ã¤ã«åºå $Media->setup($Model); $result = $Media->make($Model, $orig_filepath);
- ä¸è¨é¢æ°ãå¼ã³åºãç®æã§ãé©å®$options['mime_type']ãè¨å®ã
app/plugins/media/views/elements/medium_edit.ctp(æ¹ä¿®Attachmentã¨ã¬ã¡ã³ã)
$file = $upfile->file( 'filter/'.$previewVersion, $item, array( 'model_name' => $model, + 'mime_type' => 'image/jpeg', ) );