Generate base64 representation of image
@param string $image
@param string $mime
@return string
490080
public static function getDataURI($image, $mime = '') {
        return 'data: ' . (function_exists('mime_content_type') ? mime_content_type($image) : $mime) . ';base64,' . base64_encode(file_get_contents($image));
    }
339600
function(canvas) {
            var base64 = canvas.toDataURL('image/jpeg', options.jpegQuality)
                .replace(/^data:image\/(png|jpeg|jpg|gif);base64,/, '');
            imageData = base64toBlob(base64, 'image/jpeg');       // Byte array
        }
1096073
public function generateExtension($file = null)
    {
        if (is_string($file)) {
            if (in_array($file, $this->acceptedMimetypes())) {
                $mime = $file;
            } else {
                $mime = $this->mimetypeFor($file);
            }
        } else {
            $mime = $this->mimetype();
        }

        switch ($mime) {
            case 'image/gif':
                return 'gif';

            case 'image/jpg':
            case 'image/jpeg':
            case 'image/pjpeg':
                return 'jpg';

            case 'image/png':
                return 'png';

            case 'image/svg+xml':
                return 'svg';

            case 'image/webp':
                return 'webp';
        }
    }
1241447
private function base64ToImage($base64Data)
    {
        $img = base64_decode($base64Data);
        $this->fileName = time().rand(1, 10000).'.png';
        $this->fullName = $this->getFolder().'/'.$this->fileName;
        if (!file_put_contents($this->fullName, $img)) {
            $this->stateInfo = $this->getStateInfo('IO');

            return;
        }
        $this->oriName = '';
        $this->fileSize = strlen($img);
        $this->fileType = '.png';
    }
943364
public static String imgToBase64StrWithPrefix(BufferedImage image, String formatName) {
        formatName = formatName != null ? formatName : "jpeg";
        return String.format("data:image/%s;base64,%s", formatName, imgToBase64Str(image, formatName));
    }
1299379
@Nonnull
  public static String rescaleImageAndEncodeAsBase64(@Nonnull Image image, final int maxSize) throws IOException {
    final int width = image.getWidth(null);
    final int height = image.getHeight(null);

    final int maxImageSideSize = maxSize > 0 ? maxSize : Math.max(width, height);

    final float imageScale = width > maxImageSideSize || height > maxImageSideSize ? (float) maxImageSideSize / (float) Math.max(width, height) : 1.0f;

    if (!(image instanceof RenderedImage) || Float.compare(imageScale, 1.0f) != 0) {
      final int swidth;
      final int sheight;

      if (Float.compare(imageScale, 1.0f) == 0) {
        swidth = width;
        sheight = height;
      } else {
        swidth = Math.round(imageScale * width);
        sheight = Math.round(imageScale * height);
      }

      final BufferedImage buffer = new BufferedImage(swidth, sheight, BufferedImage.TYPE_INT_ARGB);
      final Graphics2D gfx = (Graphics2D) buffer.createGraphics();

      gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      gfx.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
      gfx.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
      gfx.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
      gfx.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
      gfx.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);

      gfx.drawImage(image, AffineTransform.getScaleInstance(imageScale, imageScale), null);
      gfx.dispose();
      image = buffer;
    }

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
      if (!ImageIO.write((RenderedImage) image, "png", bos)) {
        throw new IOException("Can't encode image as PNG");
      }
    } finally {
      IOUtils.closeQuietly(bos);
    }
    return Utils.base64encode(bos.toByteArray());
  }
996305
public function imagePath($image)
    {
        if (!$image) {
            return '';
        }

        $parts = explode(';', $image);
        $fileId = $parts[0];

        // deliver original file
        $src = $this->router->generate('frontendmedia_inline', ['fileId' => $fileId], UrlGeneratorInterface::ABSOLUTE_PATH);

        return $src;
    }
946934
final public function dataURI($as = null)
	{
		$mime = is_int($as) ? image_type_to_mime_type($as) : $this->_image_mime;
		return 'data:' . $mime . ';base64,' . base64_encode($this->imageAsBinary($as));
	}
938021
public function blob($quality = 100, $mime = null)
    {
        $imageBlob = '';

        $filename = pathinfo($this->sourceImageFile->getBasename(), PATHINFO_FILENAME);
        $extension = pathinfo($this->sourceImageFile->getBasename(), PATHINFO_EXTENSION);

        if (empty($mime)) {
            $mime = $this->sourceImageFile->getMime();
            $mime = is_array($mime) ? $mime[ 0 ] : $mime;

            $extension = $this->getMimeExtension($mime);
        }

        header('Content-Disposition: filename=' . $filename . '.' . $extension);

        if ($this->save($tempImageFilePath = rtrim(sys_get_temp_dir(),
                DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $filename . '.' . $extension,
            $quality)
        ) {
            $imageBlob = readfile($tempImageFilePath);
            unlink($tempImageFilePath);
        }

        return $imageBlob;
    }
1283711
private function validMimeImage($extension, $mimes)
    {
        if (is_array($mimes)) {
            foreach ($mimes as $mime) {
                if (!strstr($mime, 'image/')) {
                    throw new \InvalidArgumentException(htmlspecialchars(
                        "The extension $extension is not an image extension."
                    ));
                }
            }
        } else {
            if (!strstr($mimes, 'image/')) {
                throw new \InvalidArgumentException(htmlspecialchars(
                    "The extension $extension is not an image extension."
                ));
            }
        }
    }
821878
protected function getStorageUrl($image): string
    {
        if (is_array($image)) {
            array_unshift($image, 'storage');
        } else {
            $image = 'storage/' . ltrim($image);
        }

        return $this->url->to($image);
    }
613370
public function image64($path)
    {
        $file = new File($path, false);
        
        if (!$file->isFile() || 0 !== strpos($file->getMimeType(), 'image/')) {
            return;
        }
        
        $binary = file_get_contents($path);
        
        return sprintf('data:image/%s;base64,%s', $file->guessExtension(), base64_encode($binary));
    }
809330
public function imageUrl($image)
    {
        if (!$image) {
            return '';
        }

        $parts = explode(';', $image);
        $fileId = $parts[0];

        // deliver original file
        $src = $this->router->generate('frontendmedia_inline', ['fileId' => $fileId], UrlGeneratorInterface::ABSOLUTE_URL);

        return $src;
    }
628339
def _inline_image(image, mime_type=None):
    
    file = StringValue(image).value
    mime_type = StringValue(mime_type).value or mimetypes.guess_type(file)[0]
    path = None
    if callable(STATIC_ROOT):
        try:
            _file, _storage = list(STATIC_ROOT(file))[0]
            path = _storage.open(_file)
        except:
            pass
    else:
        _path = os.path.join(STATIC_ROOT, file)
        if os.path.exists(_path):
            path = open(_path, 'rb')
    if path:
        url = 'data:' + mime_type + ';base64,' + base64.b64encode(path.read())
    url = url = '%s%s?_=%s' % (STATIC_URL, file, 'NA')
    inline = 'url("%s")' % escape(url)
    return StringValue(inline)
843417
public function imageExtension($image)
    {
        $filename = $image;
        $extension = explode('.', $filename);
        $ext = strtolower(end($extension));

        return $ext;
    }
1246911
protected function createImageCanvas($image)
    {
        $this->type = $this->mime->type($image, 1);
            
        $this->imageSize = ! isset($this->width) ? getimagesize($image) : [$this->width ?? 0, $this->height ?? 0];

        $this->canvas = $this->createFrom($image,
        [
            # For type gd2p
            'x'      => $this->x      ?? 0,
            'y'      => $this->y      ?? 0,
            'width'  => $this->width  ?? $this->imageSize[0],
            'height' => $this->height ?? $this->imageSize[1]
        ]);
    }
1036452
public function setMime($mime)
    {
        if (!empty($mime)) {
            $this->setContentType(
                Mime::getFullMime($mime)
            );
        }

        return $this;
    }