public function uploadAction() {
$request = $this->getRequest();
if ($request->isPost()) {
$adapter = new \Zend\File\Transfer\Adapter\Http();
$adapter->addValidator('Size', false, array('min' => UPLOAD_IMAGE_MIN_SIZE, 'max' => UPLOAD_IMAGE_MAX_SIZE));
$adapter->addValidator('MimeType', true, array('image/jpeg'));
$adapter->addValidator('Count', false, array('min' =>1, 'max' => 1));
$adapter->addValidator('IsImage', false, 'jpeg');
$adapter->setDestination(UPLOAD_IMAGE_PATH . '/' . IMAGE_PATH_DEFAULT);
foreach($adapter->getFileInfo() as $file => $info) {
if ($adapter->isValid($file)) {
$name = $adapter->getFileName($file);
$fileName = CUSTOMER_ID . '_' . time() . '_' . $info['name'];
$imageDefault = UPLOAD_IMAGE_PATH . '/' . IMAGE_PATH_DEFAULT . '/' . $fileName;
$imageMedium = UPLOAD_IMAGE_PATH . '/' . IMAGE_PATH_MEDIUM . '/' . $fileName;
$imageSmall = UPLOAD_IMAGE_PATH . '/' . IMAGE_PATH_SMALL . '/' . $fileName;
$adapter->addFilter(
new \Zend\Filter\File\Rename(array('target' => $imageDefault,
'overwrite' => true)),
null, $file
);
if ($adapter->receive($file)) {
$image = new \Imagick();
/**
* process with medium
*/
$image->readImage($imageDefault);
$imageprops = $image->getImageGeometry();
if ($imageprops['width'] <= UPLOAD_SIZE_MEDIUM_WIDTH && $imageprops['height'] <= UPLOAD_SIZE_MEDIUM_HEIGHT) {
$image->writeImage($imageMedium);
} else {
$image->resizeImage(UPLOAD_SIZE_MEDIUM_WIDTH, UPLOAD_SIZE_MEDIUM_HEIGHT, $image::FILTER_LANCZOS, 0.9, true);
$image->writeImage($imageMedium);
}
/**
* process with small
*/
$image->readImage($imageDefault);
$imageprops = $image->getImageGeometry();
if ($imageprops['width'] <= UPLOAD_SIZE_SMALL_WIDTH && $imageprops['height'] <= UPLOAD_SIZE_SMALL_HEIGHT) {
$image->writeImage($imageSmall);
} else {
$image->resizeImage(UPLOAD_SIZE_SMALL_WIDTH, UPLOAD_SIZE_SMALL_HEIGHT, $image::FILTER_LANCZOS, 0.9, true);
$image->writeImage($imageSmall);
}
}
}
}
}
die;
}