/** * @param $fileUrl * * @return string * @throws \PHPImageWorkshop\Core\Exception\ImageWorkshopLayerException * @throws \PHPImageWorkshop\Exception\ImageWorkshopException */ private function resize($fileUrl) { if (!$this->allowedDimensions) { include projectRoot . '/conf/allowedImageSizes.conf'; } $modificator = ''; $returnTo = ''; $file = explode('/', $fileUrl); $fileName = array_pop($file); array_pop($file); $size = array_pop($file); $file = implode('/', $file); $folder = rtrim(documentRoot, '/') . BM_C_IMAGE_FOLDER . $file . '/' . $size . '/' . mb_substr($fileName, 0, 2) . '/'; @mkdir($folder, 0777, true); bmTools::chmodPath(BM_C_IMAGE_FOLDER . $file . '/' . $size . '/' . mb_substr($fileName, 0, 2), 0777); $originFile = rtrim(documentRoot, '/') . BM_C_IMAGE_FOLDER . $file . '/originals/' . mb_substr($fileName, 0, 2) . '/' . $fileName; $url = BM_C_IMAGE_FOLDER . $file . '/' . $size . '/' . mb_substr($fileName, 0, 2) . '/' . $fileName; if (in_array($size, $this->allowedDimensions) && file_exists($originFile)) { $geometry = $this->getGeometry($originFile, $size); if ($geometry != 'copy') { imagemagick_convert(' -resize ' . $geometry . ' ' . $originFile . ' ' . $folder . $fileName); } else { copy($originFile, $folder . $fileName); } exec('chmod 0777 ' . $folder . $fileName); $returnTo = $url; } return $returnTo; }
public function addObjectImage($imageGroup, $file, $local = false) { $name = $type = $tmp_name = $error = $size = []; extract($file); if (UPLOAD_ERR_NO_FILE != $error) { $errorMessage = $this->_isUploadFile($error); if ($errorMessage) { return $errorMessage; } $nameFile = $name; $nameFile = pathinfo($nameFile); $extensionFile = mb_strtolower($nameFile['extension']); $extensionFile = $extensionFile == 'jpeg' ? 'jpg' : $extensionFile; $nameFile = $nameFile['filename']; $tmpNameFile = $tmp_name; $sizeFile = $size; $fileName = sha1(time() . sha1($nameFile)) . '.' . $extensionFile; $fileSub = mb_substr($fileName, 0, 2); $folder = rtrim(documentRoot, '/') . BM_C_IMAGE_FOLDER . $imageGroup . '/originals/' . $fileSub . '/'; if (!is_dir($folder)) { mkdir($folder, 0777, true); bmTools::chmodPath(BM_C_IMAGE_FOLDER . $imageGroup . '/originals/' . $fileSub, 0777); } if ($local) { if (!copy($tmpNameFile, $folder . $fileName)) { return "Файл не смог загрузиться в ({$folder})"; } } else { if (!move_uploaded_file($tmpNameFile, $folder . $fileName)) { return "Файл не смог загрузиться в ({$folder})"; } } chmod($folder . $fileName, 0777); list($width, $height) = getimagesize($folder . $fileName); $image = new bmImage($this->application); $image->name = $nameFile; $image->caption = $nameFile; $image->fileName = $fileName; $image->size = $sizeFile; $image->width = $width; $image->height = $height; $image->save(); $image->addLinkObject($this->objectName, $this->properties['identifier'], $imageGroup); return $image; } return null; }