public function addAction() { $form = new ImageForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $image = new Image(); $form->setInputFilter($image->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $image->exchangeArray($form->getData()); $this->getImageTable()->saveImage($image); // Redirect to list of albums return $this->redirect()->toRoute('image'); } } return array('form' => $form); }
/** * (non-PHPdoc) * @param Image $image * @see \Image\Filter\ImageFilterInterface::filter() */ public function filter(Image $image) { $width = $this->getWidth(); $height = $this->getHeight(); $tempimage = imagecreatetruecolor($width, $height); if (!imagecopyresampled($tempimage, $image->getSource(), 0, 0, 0, 0, $width, $height, $image->getWidth(), $image->getHeight())) { return false; } imagedestroy($image->getSource()); $image->setSource($tempimage); $image->setWidth($width); $image->setHeight($height); return true; }
public function testImageInitialState() { $image = new Image('./module/Image/test/image.png', ''); //$this->assertFalse($image->getSource()); $this->assertEquals($image->getWidth(), 1499); $this->assertEquals($image->getHeight(), 803); $this->assertEquals($image->getMime(), 'image/png'); $this->assertNull($image->getOutputFormat()); $image->getSource(); $this->assertEquals($image->getOutputFormat(), 'png'); }
public function addAction() { $form = new ImageForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $image = new Image(); $form->setInputFilter($image->getInputFilter()); $nonFile = $request->getPost()->toArray(); $File = $this->params()->fromFiles('lien'); $names = $File['name']; echo $names; $form->setData($request->getPost()); $data = array_merge($nonFile, array('fileupload' => $File['name'])); if ($form->isValid()) { $image->exchangeArray($form->getData()); $this->getImageTable()->saveImage($image); // Redirect to list of images return $this->redirect()->toRoute('image'); } } return array('form' => $form); }
/** * * @param Image $image * @return boolean */ protected function dimensionsScale(Image $image) { $aspect = $image->getHeight() / $image->getWidth(); $width = $this->getWidth(); $height = $this->getHeight(); $upscale = $this->getUpscale(); // Calculate one of the dimensions from the other target dimension, // ensuring the same aspect ratio as the source dimensions. If one of the // target dimensions is missing, that is the one that is calculated. If both // are specified then the dimension calculated is the one that would not be // calculated to be bigger than its target. if ($width && !$height || $width && $height && $aspect < $height / $width) { $height = (int) round($width * $aspect); } else { $width = (int) round($height / $aspect); } // Don't upscale if the option isn't enabled. if (!$upscale && ($width >= $image->getWidth() || $height >= $image->getHeight())) { return false; } $this->setWidth($width); $this->setHeight($height); return true; }
public function UpdateAction($id) { //Since we don't have laravel's input class registered, we'll just use what I started with. $body = $this->detectRequestBody(); $image = json_decode(stream_get_contents($body), true); $thisimg = Image::findOrFail($id); //set each thing on image to correct value foreach ($thisimg->getFillable() as $key) { if (isset($image[$key])) { $thisimg->{$key} = $image[$key]; } } //var_dump($thisimg); //and save it $thisimg->save(); //return the json object return $thisimg->toJSON(); }
public function addAction() { $logged = $this->getConnection(); $form = new ImageForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $image = new Image(); $form->setInputFilter($image->getInputFilter()); $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); $form->setData($post); if ($form->isValid()) { $data = $form->getData(); //On créer la procédure pour renomer l'image $filter = new \Zend\Filter\File\Rename(array("source" => getcwd() . '/public/img/BanqueImage/' . $data['lien']['name'], "target" => getcwd() . '/public/img/BanqueImage', "randomize" => true)); $adapter = new \Zend\File\Transfer\Adapter\Http(); $adapter->setDestination(getcwd() . '/public/img/BanqueImage/'); if ($adapter->receive($data['lien']['name'])) { //On renomme l'image pour éiter les doublons $imageName = basename($filter->filter(getcwd() . '/public/img/BanqueImage/' . $data['lien']['name'])); $saveImage = array('idMembre' => $logged, 'lien' => $imageName); $image->exchangeArray($saveImage); $this->getImageTable()->saveImage($image); } // Redirect to list of images return $this->redirect()->toRoute('image', array('action' => 'membre', 'id' => $logged)); } } return array('form' => $form); }
/** * * @param Image $image */ private function crop($image) { $scale = max($this->getWidth() / $image->getWidth(), $this->getHeight() / $image->getHeight()); $x = ($image->getWidth() * $scale - $this->getWidth()) / 2; $y = ($image->getHeight() * $scale - $this->getHeight()) / 2; if ($this->getValign()) { switch ($this->getValign()) { case 'top': $y = 0; break; case 'bottom': $y = $image->getHeight() * $scale - $this->getHeight(); break; } } if ($this->getAlign()) { $x = ($image->getWidth() * $scale - $this->getWidth()) / 2; } $options = array('offsetX' => $x, 'pffsetY' => $y, 'width' => $this->getWidth(), 'height' => $this->getHeight()); $filter = new Crop(); $filter->setOptions($options); return $filter->filter($image); }
/** * * @param Image $image * @see \Image\Filter\Resize::filter() */ public function filter(Image $image) { $aspect = $image->getHeight() / $this->getWidth(); if (empty($this->getHeight())) { $this->setHeight($this->getWidth() / $aspect); } if (empty($this->getWidth())) { $this->setWidth($this->getHeight() * $aspect); } $tempimage = imagecreatetruecolor($this->getWidth(), $this->getHeight()); if (!imagecopyresampled($tempimage, $image->getSource(), 0, 0, $this->getOffsetX(), $this->getOffsetY(), $this->getWidth(), $this->getHeight(), $this->getWidth(), $this->getHeight())) { return false; } imagedestroy($image->getSource()); $image->setSource($tempimage); $image->setWidth($this->getWidth()); $image->setHeight($this->getHeight()); return true; }