【发布时间】:2014-05-13 15:28:08
【问题描述】:
我正在尝试在我的应用程序中实现 Miles Johnson 出色的上传器组件。但问题是:根据上传图片的尺寸,我需要更改调整尺寸。
我尝试在回调中修改转换:
public $actsAs = array(
'Uploader.Attachment' => array(
'image' => array(
'nameCallback' => 'formatName',
'tempDir' => TMP,
'uploadDir' => UPLOADDIR,
'finalPath' => '/img/photos/',
'overwrite' => false,
'stopSave' => true,
'allowEmpty' => false,
'transforms' => array(
array(
'class' => 'exif',
'self' => true
),
'image_sized' => array(
'class' => 'resize',
'nameCallback' => 'transformSizedNameCallback',
'width' => 1680,
'height' => 980,
'aspect' => true
)
)
)
),
'Uploader.FileValidation' => array(
'image' => array(
'extension' => array(
'value' => array('jpg', 'png', 'jpeg'),
'error' => 'Nicht unterstütztes Dateiformat - bitte JPG- oder PNG-Datei hochladen.'
),
'minHeight' => array(
'value' => 980,
'error' => 'Das Bild muss mindestens 980 Pixel hoch sein.'
),
'minWidth' => array(
'value' => 980,
'error' => 'Das Bild muss mindestens 980 Pixel breit sein.'
),
'required' => array(
'value' => true,
'error' => 'Bitte wählen Sie ein Bild aus.'
)
)
)
);
public function beforeTransform($options) {
if($options['dbColumn'] == 'image_sized') {
if($height > $width) {
$options['width'] = 980;
$options['height'] = 1680;
}
}
return $options;
}
我能够确定正确的变换,但是如何访问要在 beforeTransform 内变换的图像的尺寸?我从哪里获得$width 和$height?
【问题讨论】: