/** * Database insert treatment * * @param array $datas * @return \Mcwork\Model\FsUpload */ public function preparedInsert(array $datas) { $mcSerialize = new HandleSerializeDatabase(); $this->addInsert('metaCoding', $mcSerialize::STD_METHOD); if (isset($this->insert['mediaAlternate'])) { $this->addInsert('mediaAlternate', $mcSerialize->execSerialize($this->insert['mediaAlternate'])); } else { $this->addInsert('mediaAlternate', ' '); } $fields = array(); $attribs = array(); if (in_array($this->ext, $this->imageExtensions)) { $metas = array('alt' => $this->mediaName); $fields = $this->getMediaAttributeFields('images'); $size = new Size($this->targetPathFileName); $size->imgSize(); $attribs['dimensions'] = array('height' => $size->getHeight(), 'width' => $size->getWidth()); $this->addInsert('mediaDimensions', $size->getWidth() . 'x' . $size->getHeight()); } else { $metas = array('linkname' => $this->mediaName); $fields = $this->getMediaAttributeFields('files'); } if (!empty($datas) && !empty($fields)) { foreach ($fields as $field) { if (isset($datas[$field])) { $metas[$field] = $datas[$field]; } } } if (!empty($attribs)) { $this->addInsert('mediaAttribute', $mcSerialize->execSerialize($attribs)); } $this->addInsert('mediaMetas', $mcSerialize->execSerialize($metas)); return $this; }
public function multipleUpload($fs, $k, $fsTmpName) { $this->addInsert('mediaName', $fs['file']['name'][$k]); $this->setMediaName($fs['file']['name'][$k]); $this->addInsert('mediaType', $fs['file']['type'][$k]); $this->setMediaType($fs['file']['type'][$k]); $this->addInsert('mediaSizes', $fs['file']['size'][$k]); if (false === $this->moveUploadFile($fsTmpName, $this->buildTargetFile($this->buildTargetName($fs['file']['name'][$k])))) { throw new ErrorLogicModelException('Error upload file'); } else { if (in_array($this->ext, $this->imageExtensions)) { $imageFile = Clean::get($this->getTargetPathFileName()); $imgSize = new Size($imageFile); $imgSize->imgSize(); if ($this->resizeImage > 0) { $resize = new \ContentinumComponents\Images\CalculateResize($this->getResizeImage(), $imgSize->getWidth(), $imgSize->getHeight()); $nSize = $resize->getNewSize(); $nWidth = $nSize['width']; $nHeight = $nSize['height']; } else { $nWidth = $imgSize->getWidth(); $nHeight = $imgSize->getHeight(); } $newImage = @imagecreatetruecolor($nWidth, $nHeight); switch ($this->ext) { case 'JPG': case 'JPEG': case 'jpeg': case 'jpg': $jpegOptim = new \PHPImageOptim\Tools\Jpeg\JpegOptim(); $jpegOptim->setBinaryPath('/usr/bin/jpegoptim'); $jpegOptim->setOptimisationLevel(3); imagecopyresampled($newImage, imagecreatefromjpeg($imageFile), 0, 0, 0, 0, $nWidth, $nHeight, $imgSize->getWidth(), $imgSize->getHeight()); imagejpeg($newImage, $imageFile, $this->getImageQuality()); $optim = new \PHPImageOptim\PHPImageOptim(); $optim->setImage($imageFile); $optim->chainCommand($jpegOptim); $optim->optimise(); break; case "PNG": case "png": if ($this->resizeImage > 0) { imageAlphaBlending($newImage, false); imageSaveAlpha($newImage, true); imagecopyresampled($newImage, imageCreateFromPng($imageFile), 0, 0, 0, 0, $nWidth, $nHeight, $imgSize->getWidth(), $imgSize->getHeight()); imagepng($newImage, $imageFile); } $pngQuant = new \PHPImageOptim\Tools\Png\PngQuant(); $pngQuant->setBinaryPath('/usr/bin/pngquant'); $optim = new \PHPImageOptim\PHPImageOptim(); $optim->setImage($imageFile); $optim->chainCommand($pngQuant); $optim->optimise(); break; case "GIF": case "gif": if ($this->resizeImage > 0) { imageAlphaBlending($newImage, false); imageSaveAlpha($newImage, true); imagecopyresampled($newImage, imagecreatefromgif($imageFile), 0, 0, 0, 0, $nWidth, $nHeight, $imgSize->getWidth(), $imgSize->getHeight()); imagegif($newImage, $imageFile); } $gifsicle = new \PHPImageOptim\Tools\Gif\Gifsicle(); $gifsicle->setBinaryPath('/usr/bin/gifsicle'); $optim = new \PHPImageOptim\PHPImageOptim(); $optim->setImage($imageFile); $optim->chainCommand($gifsicle); $optim->optimise(); break; default: break; } if ($this->resizeImage > 0) { $this->addInsert('mediaDimensions', $nWidth . 'x' . $nHeight, true); } $this->addInsert('mediaSizes', filesize($imageFile), true); } if (in_array($this->ext, $this->imageExtensions)) { return 1; } } }