public function testGetImageFileNameWithDimensions() { $filename = 'test.png'; $this->assertEquals('123x321 test.png', ImageFileModelUtil::getImageFileNameWithDimensions($filename, 123, 321)); $filename = '4512x12 test.png'; $this->assertEquals('123x321 test.png', ImageFileModelUtil::getImageFileNameWithDimensions($filename, 123, 321)); }
public function actionModalEdit($id) { if (!Yii::app()->request->isAjaxRequest) { throw new NotSupportedException(); } $form = new ImageEditForm(); $imageFileModel = ImageFileModel::getById((int) $id); Yii::app()->getClientScript()->setToAjaxMode(); if (isset($_POST['ajax']) && $_POST['ajax'] == 'image-edit-form') { $errors = ZurmoActiveForm::validate($form); if ($form->hasErrors()) { echo $errors; Yii::app()->end(); } } elseif (isset($_POST['ImageEditForm'])) { $tempFilePath = tempnam(sys_get_temp_dir(), 'edit_image_'); $form->attributes = $_POST['ImageEditForm']; $originalImageFileModel = ImageFileModel::getById((int) $id); $contents = WideImage::load($originalImageFileModel->fileContent->content)->resize($form->imageWidth, $form->imageHeight)->crop($form->cropX, $form->cropY, $form->cropWidth, $form->cropHeight)->asString(str_replace('image/', '', $originalImageFileModel->type)); file_put_contents($tempFilePath, $contents); $imageProperties = getimagesize($tempFilePath); $fileUploadData = ImageFileModelUtil::saveImageFromTemporaryFile($tempFilePath, ImageFileModelUtil::getImageFileNameWithDimensions($originalImageFileModel->name, (int) $imageProperties[0], (int) $imageProperties[1])); echo CJSON::encode($fileUploadData); } else { $modalListLinkProvider = $this->getModalListLinkProvider(); $form->id = $imageFileModel->id; $form->imageWidth = $imageFileModel->width; $form->imageHeight = $imageFileModel->height; $form->cropX = 0; $form->cropY = 0; $form->cropWidth = $imageFileModel->width; $form->cropHeight = $imageFileModel->height; $form->lockImageProportion = true; if ($imageFileModel->isEditableByCurrentUser()) { $view = new ImageEditView($this, $form, $imageFileModel, $modalListLinkProvider); $view = new ModalView($this, $view); } else { $view = new AccessFailureView(); } echo $view->render(); } }