code: public function saveImageToPng($gdResource, $path = null, $filename = null)
      {
          if (null === $path) {
              $path = $this->basePath;
          }
  
          $this->ensureDirectoryExists($path);
  
          if (null === $filename) {
              $filename = md5(uniqid('imagepng', true)) . '.png';
          }
  
          $fullPath = $path . '/' . $filename;
          $result = imagepng($gdResource, $fullPath, 5);
  
          if (!$result) {
              throw new \RuntimeException(sprintf('Could not save image to %s', $fullPath));
          }
  
          $file = new File($fullPath, $filename, 'image/png', filesize($fullPath));
  
          return $file;
      }
docs: @param resource $gdResource  A GD image resource
  @param string $path          The path (no filename) to save the image
  @param string $filename      The filename to save the image as
  
  @throws \RuntimeException
  @return \Orkestra\Bundle\ApplicationBundle\Entity\File