Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for jpeg data uri in $canvas->image() #2783

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidsev
Copy link

Other image formats already work with data uri's, but jpeg's don't as cpdf->addJpegFromFile uses file_exists.
This change adds support for data uri's to addJpegFromFile.

Other image formats already work with data uri's, but jpeg's don't as
cpdf->addJpegFromFile uses file_exists.
This change adds support for data uri's to addJpegFromFile.
@bsweeney
Copy link
Member

Data URIs are handled by the Dompdf image caching logic, not the canvas library.

The following seems to work fine:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
  <img src="data:img/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gNjUK/9sAQwALCAgKCAcLCgkKDQwLDREcEhEPDxEiGRoUHCkkKyooJCcnLTJANy0wPTAnJzhMOT1DRUhJSCs2T1VORlRAR0hF/9sAQwEMDQ0RDxEhEhIhRS4nLkVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVF/8AAEQgACgAKAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8Ak0ifUoJY4b24DSK/+rVyNox7cfhXUi6hAALjP1rh42b+2Sdxz57Dr9a0JCfMfnuaSd9ypKx//9k=" />
</body>
</html>

@davidsev
Copy link
Author

That works for images in HTML, but it doesn't work for embedded php or callbacks.

For example, the following code doesn't work, but works fine with a png or bmp:

$dompdf->setCallbacks([[
    'event' => 'end_page_render',
	'f' => function ($info) {
		$canvas = $info['canvas'];
		$canvas->image('data:image/jpeg;base64,'.base64_encode(file_get_contents('tests/_files/jamaica.jpg')),20,80,100,100);
		$canvas->image('tests/_files/jamaica.jpg',20,200,100,100);
    }
]]);

The difference in behaviour between image formats suggests that this isn't intentional behaviour, and the wiki also implies that this should work.

Maybe a better solution would be to update the CPDF adapter to use the same image caching as the HTML uses?

@bsweeney bsweeney added this to the 1.2.1 milestone Feb 17, 2022
@bsweeney
Copy link
Member

Thanks for the additional info. I'll take another look at the change.

@bsweeney bsweeney modified the milestones: 1.2.1, 2.0.1 Mar 16, 2022
@bsweeney bsweeney modified the milestones: 2.0.1, 2.0.2 Aug 25, 2022
@bsweeney bsweeney modified the milestones: 2.0.2, 2.0.3 Jan 29, 2023
@bsweeney bsweeney modified the milestones: 2.0.4, 2.0.5 Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants