make original photo

@param $photo
@param $path
@return string
545353
protected function original($photo, $path)
    {
        $this->makeDirectoryBeforeUpload($path, false);
        Image::make( $photo )->encode('jpg')->save($path . '/' . $this->fileName, 100 );
        return '/' . $path . '/' . $this->fileName;
    }
766873
public function destroy(Photo $photo)
    {
        $this->deleteEntry($photo, request());

        log_activity('Photo Deleted', 'A Photo was successfully deleted', $photo);

        return redirect_to_resource();
    }
31711
public function getOriginalImagePath()
    {
        $savePath = Yii::getAlias($this->_savePathAlias);
        $image = $this->_oldImage;

        return static::addPostfixToFile($savePath . DIRECTORY_SEPARATOR . $image, '_original');
    }
816458
public function convert( $path_to_pdf, $path_to_jpg, $resize = '2500x3750' ) {

		// Convert using Imagemagick (TODO: fix jagged ugly fonts)
		// $command = PB_CONVERT_COMMAND . ' ' . escapeshellarg( $pathToPdf ) . " -density 96 -resize {$resize} -define jpeg:extent=2MB " . escapeshellarg( $pathToJpg );

		// Convert using pdfToPpm
		list( $x, $y ) = explode( 'x', $resize );
		$path_to_jpg = rtrim( $path_to_jpg, '.jpg' ); // Remove extension because it is auto-generated by pdfToPpm
		$command = PB_PDFTOPPM_COMMAND . ' -jpeg -singlefile -scale-to-x ' . (int) $x . ' -scale-to-y ' . (int) $y . ' ' . escapeshellarg( $path_to_pdf ) . ' ' . escapeshellarg( $path_to_jpg );

		// Execute command
		$output = [];
		$return_var = 0;
		exec( $command, $output, $return_var ); // @codingStandardsIgnoreLine

		$post = ( new \Pressbooks\Metadata() )->getMetaPost();

		if ( $post ) {
			$jpg = \Pressbooks\Utility\create_tmp_file();

			copy( $path_to_jpg . '.jpg', $jpg );

			$old_id = \Pressbooks\Image\attachment_id_from_url( get_post_meta( $post->ID, 'pb_cover_image', true ) );
			if ( $old_id ) {
				wp_delete_attachment( $old_id, true );
			}

			if ( ! function_exists( 'media_handle_sideload' ) ) {
				require_once( ABSPATH . 'wp-admin/includes/image.php' );
				require_once( ABSPATH . 'wp-admin/includes/file.php' );
				require_once( ABSPATH . 'wp-admin/includes/media.php' );
			}

			$pid = media_handle_sideload(
				[
					'name' => 'cover.jpg',
					'tmp_name' => $jpg,
				], 0
			);
			if ( is_wp_error( $pid ) ) {
				throw new \Exception(
					$pid->get_error_message()
				);
			}

			$src = wp_get_attachment_url( $pid );

			if ( false === $src ) {
				throw new \Exception( 'No attachment url.' );
			}

			update_post_meta( $post->ID, 'pb_cover_image', $src );
		}

		if ( ! empty( $output ) ) {
			// @codingStandardsIgnoreStart
			debug_error_log( $command );
			debug_error_log( print_r( $output, true ) );
			// @codingStandardsIgnoreEnd
		}
	}
1039245
protected function createTmb($path, $stat) {
		if (!$stat || !$this->canCreateTmb($path, $stat)) {
			return false;
		}

		$name = $this->tmbname($stat);
		$tmb  = $this->tmbPath.DIRECTORY_SEPARATOR.$name;

		// copy image into tmbPath so some drivers does not store files on local fs
		if (($src = $this->_fopen($path, 'rb')) == false) {
			return false;
		}

		if (($trg = fopen($tmb, 'wb')) == false) {
			$this->_fclose($src, $path);
			return false;
		}

		while (!feof($src)) {
			fwrite($trg, fread($src, 8192));
		}

		$this->_fclose($src, $path);
		fclose($trg);

		$result = false;
		
		$tmbSize = $this->tmbSize;
		
  		if (($s = getimagesize($tmb)) == false) {
			return false;
		}
    
    	/* If image smaller or equal thumbnail size - just fitting to thumbnail square */
    	if ($s[0] <= $tmbSize && $s[1]  <= $tmbSize) {
     	   $result = $this->imgSquareFit($tmb, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png' );

	    } else {

	    	if ($this->options['tmbCrop']) {
        
        		/* Resize and crop if image bigger than thumbnail */
	        	if (!(($s[0] > $tmbSize && $s[1] <= $tmbSize) || ($s[0] <= $tmbSize && $s[1] > $tmbSize) ) || ($s[0] > $tmbSize && $s[1] > $tmbSize)) {
    				$result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, false, 'png');
	        	}

				if (($s = getimagesize($tmb)) != false) {
					$x = $s[0] > $tmbSize ? intval(($s[0] - $tmbSize)/2) : 0;
					$y = $s[1] > $tmbSize ? intval(($s[1] - $tmbSize)/2) : 0;
					$result = $this->imgCrop($tmb, $tmbSize, $tmbSize, $x, $y, 'png');
				}

    		} else {
        		$result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, true, $this->imgLib, 'png');
        		$result = $this->imgSquareFit($tmb, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png' );
      		}

		}
		if (!$result) {
			unlink($tmb);
			return false;
		}

		return $name;
	}
732884
public function make(Image $image, string $version): Image
    {
        $config = $this->getVersionConfig($version);
        $manipulator = $this->extractManipulatorNameFromConfig($config);

        $binary = $this->manipulate($image->getBinary(), $manipulator, $config);

        return $image->modify($binary, $version);
    }
795150
public function get_img_url( $path, $default = 'img/no_img.png', $append_version = true ) {
		return empty( $path ) ? '' : $this->get_assets_url( 'img/' . $path, $default, $append_version );
	}
8666
public static function sendPhoto($photo ,$message = ''){
        self::initialize();
        $data = [
            'message' => $message,
            'source' => self::$fb->fileToUpload($photo)
        ];
        try {
            $response = self::$fb->post('/me/photos', $data, self::$page_access_token);
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
            throw new \Exception('Graph returned an error: '.$e->getMessage());
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
            throw new \Exception('Facebook SDK returned an error: '.$e->getMessage());
        }
        $graphNode = $response->getGraphNode();

        return $graphNode['id'];
    }
791284
private function createFromPng(string $path): self
    {
        $imageData = imagecreatefrompng($path);
        if (false === $imageData) {
            throw new ImageException(sprintf('Unable to create PNG image from %s!', $path));
        }
        $this->workingData = $imageData;
        $this->setTransparency(false, true);
        $this->encrypted = false;
        return $this;
    }
17847
function addPhoto($photo) {
        if (!file_exists($photo['tmp_name']) || !is_uploaded_file($photo['tmp_name'])) {
            $o = array('state' => false); 
        } else {
            
            $photos = new Zend_Gdata_Photos($this->client);
            
            $fd = $photos->newMediaFileSource($photo["tmp_name"]);
            $fd->setContentType($photo["type"]);
            
            $entry = new Zend_Gdata_Photos_PhotoEntry();
            $entry->setMediaSource($fd);
            $entry->setTitle($photos->newTitle($photo["name"]));
            
            $albumQuery = new Zend_Gdata_Photos_AlbumQuery;
            $albumQuery->setUser($this->user);
            $albumQuery->setAlbumId($this->album);
            
            $albumEntry = $photos->getAlbumEntry($albumQuery);
            
            $result = $photos->insertPhotoEntry($entry, $albumEntry);
            if ($result) {
                $o = array('state' => true, 'id' => $result->getGphotoId());                 
            } else {
                $o = array('state' => false); 
            }            
        }
        return $o;
    }
1315086
protected function createImage($path)
    {
        $path = sprintf('%s/../Resources/images/%s', __DIR__, $path);
        $file = $this->container->get('enhavo_media.factory.file')->createFromPath($path);
        return $this->container->get('enhavo_media.media.media_manager')->saveFile($file);
    }
1133017
def replace(self, photo, photo_file, **kwds):
        
        with open(photo_file, 'rb') as in_file:
            result = self._client.post("/photo/%s/replace.json" %
                                       self._extract_id(photo),
                                       files={'photo': in_file},
                                       **kwds)["result"]
        return Photo(self._client, result)
805173
public static function create($files, $path, $quality = 0)
    {
        switch( self::getFileExtension($path) )
        {
            case 'png' : 
                if( $quality > 10 )
                {
                    $quality = (int) ($quality / 10);
                }
                return imagepng($files, $path, $quality ?: 8 );
            case 'gif' : return imagegif($files, $path);
            case 'jpg' :
            case 'jpeg': 
            default    : return imagejpeg($files, $path, $quality ?: 80);
        }
    }
679548
protected function getImage( $path = null )
    {
        if ( is_null( $this->image ) )
        {
            if ( is_null( $path ) )
            {
                $this->image = Image::create(
                    $this->width,
                    $this->height
                );
            }
            else
            {
                $this->image = Image::open( $path );
            }
        }

        return $this->image;
    }
145730
private function createImageFrom($path)
    {

        $this->gdExtensionCheck();
        switch ($this->getExt()) {
            case 'jpg':
                return imagecreatefromjpeg($path);
                break;
            case 'png':
                return imagecreatefrompng($path);
                break;
            case 'gif':
                return imagecreatefromgif($path);
                break;

            default:
                return imagecreatefrompng($path);
                break;
        }

    }
792463
public static function from($path)
    {
        switch( self::getFileExtension($path) )
        {
            case 'png' : return imagecreatefrompng($path);
            case 'gif' : return imagecreatefromgif($path);
            case 'jpg' :
            case 'jpeg':
            default    : return imagecreatefromjpeg($path);
        }
    }
719057
public function thumbnail(string $path, string $thumbnail): string
    {
        // original  = /<user>/original/xx/yy/xxyyzzzz.<format>
        $fullPath = preg_replace(
            '~/' . $this->corundum->type() . '/~',
            '/thumbs/' . $thumbnail . '/',
            $path
        );

        Dir::make(dirname($fullPath));

        return $fullPath;
    }