Esempio n. 1
0
 public static function createFromUpload($basePath, $uploadPath)
 {
     $image = new Image($uploadPath);
     if (!$image->valid) {
         return null;
     }
     $targetName = self::getNewName($image->extension);
     $scaledTargetPath = $basePath . $targetName;
     $originalTargetPath = $scaledTargetPath;
     // Do we want to create a scaled down version of this image?
     if ($image->width > CONFIG::IMAGE_MAX_WIDTH) {
         $scaledWidth = CONFIG::IMAGE_MAX_WIDTH;
         $scaledHeight = $scaledWidth / $image->width * $image->height;
         $image->writeThumb($scaledTargetPath, CONFIG::IMAGE_JPEG_QUALITY, $scaledWidth, $scaledHeight, CONFIG::IMAGE_SHARPEN);
         setFileMode($scaledTargetPath);
         // We created a scaled down version, so the original has to be moved
         // in a separate big/ folder
         $originalTargetPath = $basePath . CONFIG::IMAGE_BIG_PATH . $targetName;
     }
     // If the image had an exif orientation, save the rotated version
     // and delete the original.
     if ($image->exifRotated) {
         $image->write($originalTargetPath, CONFIG::IMAGE_JPEG_QUALITY);
         unlink($uploadPath);
     } else {
         move_uploaded_file($uploadPath, $originalTargetPath);
     }
     setFileMode($originalTargetPath);
     return self::open($scaledTargetPath);
 }
Esempio n. 2
0
 public function edit($content)
 {
     // Write the new file and delete the old
     $newPath = dirname($this->path) . '/' . self::getNewName($this->extension);
     if (file_put_contents($newPath, $content)) {
         setFileMode($newPath);
         $this->delete();
         $this->path = $newPath;
     }
 }
Esempio n. 3
0
 public function createSharekey()
 {
     // Remove old sharekey, if present
     $this->removeSharekey();
     // Create a new .sharekey file with a random name
     $key = md5(rand() . time());
     $keyfile = $this->path . $key . '.sharekey';
     file_put_contents($keyfile, time());
     setFileMode($keyfile);
     $this->sharekey = $key;
     return $this->sharekey;
 }