public function crop($file, $newFilename, $context) { // var_dump($file); exit; $filename = $file['name']; $tempFile = $file['tmp_name']; // $filesize = $file['size']; $temp_file = $file['tmp_name']; $ImageEditor = ApuImageEditor::getInstance(); $custom_settings = AzulPhotoUploaderPluginConfiguration::getAPGRegisteredContextSettings($context); $default_settings = sfConfig::get('app_azul_photo_uploader_settings', null); $destinationFolder = sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $default_settings['upload_path'] . DIRECTORY_SEPARATOR . $context . DIRECTORY_SEPARATOR; $ImageEditor->setDestination($destinationFolder); $ImageEditor->setImageFile($temp_file); $ImageEditor->setFilename($newFilename); // create standard image // $ImageEditor->scale("standard_"); $ImageEditor->resize("standard_", 1000, 1000); // var_dump($custom_settings['sizes']); foreach ($custom_settings['sizes'] as $size => $dimention) { $prefix = $size . "_"; $ImageEditor->crop("{$prefix}", $dimention['width'], $dimention['height']); } if (isset($custom_settings['scale'])) { $dimentions = $custom_settings['scale']; $ImageEditor->resize("scale_", $dimentions['width'], $dimentions['height']); } }
public function getPath($size = null, $version = false) { $default_settings = sfConfig::get('app_azul_photo_uploader_settings', null); $upload_path = DIRECTORY_SEPARATOR . $default_settings['upload_path'] . DIRECTORY_SEPARATOR . strtolower($this->getContext()); $size = is_null($size) ? "" : $size . "_"; $time = date('Ymd'); $filename = $size . $this->getFilename(); $file = $upload_path . DIRECTORY_SEPARATOR . $filename; $nUploadPath = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . strtolower($this->getContext()); $nFile = $nUploadPath . DIRECTORY_SEPARATOR . $filename; if (!file_exists($nFile)) { $contexts = sfConfig::get('app_azul_photo_uploader_contexts', null); // var_dump($contexts); $context_settings = AzulPhotoUploaderPluginConfiguration::getAPGRegisteredContextSettings($this->getContext()); $first_key = key($context_settings['sizes']); $nFile = $nUploadPath . DIRECTORY_SEPARATOR . $first_key . "_" . $this->getFilename(); $file = file_exists($nFile) ? $upload_path . DIRECTORY_SEPARATOR . $first_key . "_" . $this->getFilename() : $file; // $file = $upload_path . DIRECTORY_SEPARATOR . $first_key . "_" . $this->getFilename(); } if ($version) { $file .= "?v={$time}"; } return $file; }