Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/PhabricatorImageTransformer.php
| Show All 14 Lines | return PhabricatorFile::newFromFileData( | ||||
| $image, | $image, | ||||
| array( | array( | ||||
| 'name' => 'meme-'.$file->getName(), | 'name' => 'meme-'.$file->getName(), | ||||
| 'ttl.relative' => phutil_units('24 hours in seconds'), | 'ttl.relative' => phutil_units('24 hours in seconds'), | ||||
| 'canCDN' => true, | 'canCDN' => true, | ||||
| )); | )); | ||||
| } | } | ||||
| public function executeConpherenceTransform( | |||||
| PhabricatorFile $file, | |||||
| $top, | |||||
| $left, | |||||
| $width, | |||||
| $height) { | |||||
| $image = $this->crasslyCropTo( | |||||
| $file, | |||||
| $top, | |||||
| $left, | |||||
| $width, | |||||
| $height); | |||||
| return PhabricatorFile::newFromFileData( | |||||
| $image, | |||||
| array( | |||||
| 'name' => 'conpherence-'.$file->getName(), | |||||
| 'profile' => true, | |||||
| 'canCDN' => true, | |||||
| )); | |||||
| } | |||||
| private function crasslyCropTo(PhabricatorFile $file, $top, $left, $w, $h) { | |||||
| $data = $file->loadFileData(); | |||||
| $src = imagecreatefromstring($data); | |||||
| $dst = $this->getBlankDestinationFile($w, $h); | |||||
| $scale = self::getScaleForCrop($file, $w, $h); | |||||
| $orig_x = $left / $scale; | |||||
| $orig_y = $top / $scale; | |||||
| $orig_w = $w / $scale; | |||||
| $orig_h = $h / $scale; | |||||
| imagecopyresampled( | |||||
| $dst, | |||||
| $src, | |||||
| 0, 0, | |||||
| $orig_x, $orig_y, | |||||
| $w, $h, | |||||
| $orig_w, $orig_h); | |||||
| return self::saveImageDataInAnyFormat($dst, $file->getMimeType()); | |||||
| } | |||||
| private function getBlankDestinationFile($dx, $dy) { | |||||
| $dst = imagecreatetruecolor($dx, $dy); | |||||
| imagesavealpha($dst, true); | |||||
| imagefill($dst, 0, 0, imagecolorallocatealpha($dst, 255, 255, 255, 127)); | |||||
| return $dst; | |||||
| } | |||||
| public static function getScaleForCrop( | |||||
| PhabricatorFile $file, | |||||
| $des_width, | |||||
| $des_height) { | |||||
| $metadata = $file->getMetadata(); | |||||
| $width = $metadata[PhabricatorFile::METADATA_IMAGE_WIDTH]; | |||||
| $height = $metadata[PhabricatorFile::METADATA_IMAGE_HEIGHT]; | |||||
| if ($height < $des_height) { | |||||
| $scale = $height / $des_height; | |||||
| } else if ($width < $des_width) { | |||||
| $scale = $width / $des_width; | |||||
| } else { | |||||
| $scale_x = $des_width / $width; | |||||
| $scale_y = $des_height / $height; | |||||
| $scale = max($scale_x, $scale_y); | |||||
| } | |||||
| return $scale; | |||||
| } | |||||
| private function applyMemeToFile( | private function applyMemeToFile( | ||||
| PhabricatorFile $file, | PhabricatorFile $file, | ||||
| $upper_text, | $upper_text, | ||||
| $lower_text) { | $lower_text) { | ||||
| $data = $file->loadFileData(); | $data = $file->loadFileData(); | ||||
| $img_type = $file->getMimeType(); | $img_type = $file->getMimeType(); | ||||
| $imagemagick = PhabricatorEnv::getEnvConfig('files.enable-imagemagick'); | $imagemagick = PhabricatorEnv::getEnvConfig('files.enable-imagemagick'); | ||||
| ▲ Show 20 Lines • Show All 295 Lines • Show Last 20 Lines | |||||