Skip to content

Instantly share code, notes, and snippets.

@pdbreen
pdbreen / cacheImageGd
Created April 27, 2023 14:46
cacheImageGd
public static function cacheImageGd(Filesystem $cache, $imageData, int $w, int $h, string $jpegName, string $webpName)
{
$srcImage = imagecreatefromstring($imageData);
$srcWidth = imagesx($srcImage);
$srcHeight = imagesy($srcImage);
$widthRatio = $w / $srcWidth;
$heightRatio = $h / $srcHeight;
$x = $y = 0;