Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Get plain image with sizes of original image
- * @return string
- */
- protected static function getPlainImage($imageElement): string
- {
- $fileName = $imageElement->fileId . '-' . $imageElement->areaWidth . 'x' . $imageElement->areaHeight;
- $img = imagecreatefromstring(base64_decode(self::PLAIN_IMAGE_BASE64));
- $sourceWidth = imagesx($img);
- $sourceHeight = imagesy($img);
- $thumb = imagecreatetruecolor($imageElement->areaWidth, $imageElement->areaHeight);
- $transparency = imagecolorallocatealpha($thumb, 255, 255, 255, 127);
- imagefilledrectangle($thumb, 0, 0, $imageElement->areaWidth, $imageElement->areaHeight, $transparency);
- imagecopyresampled($thumb, $img, 0, 0, 0, 0, $imageElement->areaWidth, $imageElement->areaHeight, $sourceWidth, $sourceHeight);
- imagejpeg($thumb, $fileName);
- $imageContent = file_get_contents($fileName);
- //Clean & destroy
- imagedestroy($img);
- imagedestroy($thumb);
- unlink($fileName);
- return 'data:image/jpeg;base64,' . base64_encode($imageContent);
- }
Add Comment
Please, Sign In to add comment