/** * Sets a new profile image by given temp file * * @param CUploadedFile $file */ public function setNew($file) { $this->delete(); ImageConverter::TransformToJpeg($file->tempName, $this->getPath('_org')); ImageConverter::Resize($this->getPath('_org'), $this->getPath('_org'), array('width' => 1134, 'mode' => 'max')); ImageConverter::Resize($this->getPath('_org'), $this->getPath(''), array('width' => $this->width, 'height' => $this->height)); }
/** * Sets a new logo image by given temp file * * @param CUploadedFile $file */ public function setNew(UploadedFile $file) { $this->delete(); move_uploaded_file($file->tempName, $this->getPath()); ImageConverter::Resize($this->getPath(), $this->getPath(), array('height' => $this->height, 'width' => 0, 'mode' => 'max', 'transparent' => $file->getExtension() == 'png' && ImageConverter::checkTransparent($this->getPath()))); }
/** * Sets a new profile image by given temp file * * @param mixed $file CUploadedFile or file path */ public function setNew($file) { if ($file instanceof \yii\web\UploadedFile) { $file = $file->tempName; } $this->delete(); ImageConverter::TransformToJpeg($file, $this->getPath('_org')); ImageConverter::Resize($this->getPath('_org'), $this->getPath('_org'), array('width' => 400, 'mode' => 'max')); ImageConverter::Resize($this->getPath('_org'), $this->getPath(''), array('width' => $this->width, 'height' => $this->height)); }
public function getPreviewImageUrl($maxWidth = 1000, $maxHeight = 1000) { $suffix = 'pi_' . $maxWidth . "x" . $maxHeight; $originalFilename = $this->getStoredFilePath(); $previewFilename = $this->getStoredFilePath($suffix); // already generated if (is_file($previewFilename)) { return $this->getUrl($suffix); } // Check file exists & has valid mime type if ($this->getMimeBaseType() != "image" || !is_file($originalFilename)) { return ""; } $imageInfo = @getimagesize($originalFilename); // Check if we got any dimensions - invalid image if (!isset($imageInfo[0]) || !isset($imageInfo[1])) { return ""; } // Check if image type is supported if ($imageInfo[2] != IMAGETYPE_PNG && $imageInfo[2] != IMAGETYPE_JPEG && $imageInfo[2] != IMAGETYPE_GIF) { return ""; } ImageConverter::Resize($originalFilename, $previewFilename, array('mode' => 'max', 'width' => $maxWidth, 'height' => $maxHeight)); return $this->getUrl($suffix); }
/** * Crop an image file to a square thumbnail. * The thumbnail will be saved with the suffix "<width>_thumb_square" * @param File $basefile the file to crop. * @param number $maxDimension limit maximum with/height. * @return string the thumbnail's url or null if an error occured. */ public static function getSquareThumbnailUrlFromFile($basefile = null, $maxDimension = 1000) { if ($basefile === null) { return; } $suffix = $maxDimension . '_thumb_square'; $originalFilename = $basefile->getStoredFilePath(); $previewFilename = $basefile->getStoredFilePath($suffix); // already generated if (is_file($previewFilename)) { return $basefile->getUrl($suffix); } // Check file exists & has valid mime type if ($basefile->getMimeBaseType() != "image" || !is_file($originalFilename)) { return ""; } $imageInfo = @getimagesize($originalFilename); // check valid image dimesions if (!isset($imageInfo[0]) || !isset($imageInfo[1])) { return ""; } // Check if image type is supported if ($imageInfo[2] != IMAGETYPE_PNG && $imageInfo[2] != IMAGETYPE_JPEG && $imageInfo[2] != IMAGETYPE_GIF) { return ""; } $dim = min($imageInfo[0], $imageInfo[1], $maxDimension); ImageConverter::Resize($originalFilename, $previewFilename, array('mode' => 'force', 'width' => $dim, 'height' => $dim)); return $basefile->getUrl($suffix); }