Кемеровские программисты php общаются здесь
Anonymous
Как изменить размер изображения при загрузке в ZF2
Сообщение
Anonymous » 09 июл 2024, 05:15
Я новичок в работе с Zend Frame, и мне нужно реализовать изменение размера изображения при загрузке в Zend Framework 2. Я пытаюсь использовать метод изменения размера изображения zf2, но у меня он не сработал.
пожалуйста, помогите?
публичная функция addAction(){
Код: Выделить всё
$form = new ProfileForm();
$request = $this->getRequest();
if ($request->isPost()) {
$profile = new Profile();
$form->setInputFilter($profile->getInputFilter());
$nonFile = $request->getPost()->toArray();
$File = $this->params()->fromFiles('fileupload');
$width = $this->params('width', 30); // @todo: apply validation!
$height = $this->params('height', 30); // @todo: apply validation!
$imagine = $this->getServiceLocator()->get('my_image_service');
$image = $imagine->open($File['tmp_name']);
$transformation = new \Imagine\Filter\Transformation();
$transformation->thumbnail(new \Imagine\Image\Box($width, $height));
$transformation->apply($image);
$response = $this->getResponse();
$response->setContent($image->get('png'));
$response
->getHeaders()
->addHeaderLine('Content-Transfer-Encoding', 'binary')
->addHeaderLine('Content-Type', 'image/png')
->addHeaderLine('Content-Length', mb_strlen($imageContent));
return $response;
$data = array_merge(
$nonFile,
array('fileupload'=> $File['name'])
);
$form->setData($data);
if ($form->isValid()) {
$size = new Size(array('min'=>100000)); //minimum bytes filesize
$adapter = new \Zend\File\Transfer\Adapter\Http();
$adapter->setValidators(array($size), $File['name']);
if (!$adapter->isValid()){
$dataError = $adapter->getMessages();
$error = array();
foreach($dataError as $key=>$row)
{
$error[] = $row;
}
$form->setMessages(array('fileupload'=>$error ));
} else {
$adapter->setDestination('./data/tmpuploads/');
if ($adapter->receive($File['name'])) { //identify the uploaded errors
$profile->exchangeArray($form->getData());
echo 'Profile Name '.$profile->profilename.' upload '.$profile->fileupload;
}
}
}
}
return array('form' => $form);
}
Относится к :-image resize zf2
Подробнее здесь:
https://stackoverflow.com/questions/243 ... ing-in-zf2
1720491321
Anonymous
Я новичок в работе с Zend Frame, и мне нужно реализовать изменение размера изображения при загрузке в Zend Framework 2. Я пытаюсь использовать метод изменения размера изображения zf2, но у меня он не сработал. пожалуйста, помогите? публичная функция addAction(){ [code] $form = new ProfileForm(); $request = $this->getRequest(); if ($request->isPost()) { $profile = new Profile(); $form->setInputFilter($profile->getInputFilter()); $nonFile = $request->getPost()->toArray(); $File = $this->params()->fromFiles('fileupload'); $width = $this->params('width', 30); // @todo: apply validation! $height = $this->params('height', 30); // @todo: apply validation! $imagine = $this->getServiceLocator()->get('my_image_service'); $image = $imagine->open($File['tmp_name']); $transformation = new \Imagine\Filter\Transformation(); $transformation->thumbnail(new \Imagine\Image\Box($width, $height)); $transformation->apply($image); $response = $this->getResponse(); $response->setContent($image->get('png')); $response ->getHeaders() ->addHeaderLine('Content-Transfer-Encoding', 'binary') ->addHeaderLine('Content-Type', 'image/png') ->addHeaderLine('Content-Length', mb_strlen($imageContent)); return $response; $data = array_merge( $nonFile, array('fileupload'=> $File['name']) ); $form->setData($data); if ($form->isValid()) { $size = new Size(array('min'=>100000)); //minimum bytes filesize $adapter = new \Zend\File\Transfer\Adapter\Http(); $adapter->setValidators(array($size), $File['name']); if (!$adapter->isValid()){ $dataError = $adapter->getMessages(); $error = array(); foreach($dataError as $key=>$row) { $error[] = $row; } $form->setMessages(array('fileupload'=>$error )); } else { $adapter->setDestination('./data/tmpuploads/'); if ($adapter->receive($File['name'])) { //identify the uploaded errors $profile->exchangeArray($form->getData()); echo 'Profile Name '.$profile->profilename.' upload '.$profile->fileupload; } } } } return array('form' => $form); } [/code] Относится к :-image resize zf2 Подробнее здесь: [url]https://stackoverflow.com/questions/24364346/how-to-resize-a-image-while-uploading-in-zf2[/url]