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

Issue reading GDImage object using \Imagine\Gd\Imagine read() method #834

Closed
jcogs-design opened this issue Nov 12, 2022 · 3 comments
Closed

Comments

@jcogs-design
Copy link

Issue description

When trying to read an existing GDImage object into an Imagine\Gd\Imagine object I get an exception
Variable does not contain a stream resource

Unclear from manual whether there is a way / how to insert a GDImage object into an Imagine object.

What version of Imagine are you using?

1.3.2

What's the PHP version you are using?

8.0.25

What's the imaging library you are using [gd/imagick/gmagick/any]?

GD2

What's the imaging library configuration

GD Version: "2.3.3"
FreeType Support: true
FreeType Linkage: "with freetype"
GIF Read Support: true
GIF Create Support: true
JPEG Support: true
PNG Support: true
WBMP Support: true
XPM Support: true
XBM Support: true
WebP Support: true
BMP Support: true
TGA Read Support: true
JIS-mapped Japanese Font Support: false

Minimal PHP code to reproduce the error:

$gd_resource = imagecreatefromstring(file_get_contents($path)); // in php 8 creates a GDImage object
$imagine_object = new Imagine\Gd\Imagine(); // Creates new Imagine GD object
$imagine_object->read($gd_resource); // Throws an error 'Variable does not contain a stream resource'
@ausi
Copy link
Contributor

ausi commented Nov 12, 2022

Imagine\Gd\Imagine::read() can only handle resources that point to files, not GD resource objects.
So your code should probably look like this:

$file_contents = file_get_contents($path);
$imagine_object = new Imagine\Gd\Imagine();
$imagine_object->load($file_contents);

Or if you need to handle existing GD resources you could use the class factory to create an image from that:

$gd_resource = imagecreatefromstring(file_get_contents($path)); // in php 8 creates a GDImage object
(new Imagine\Factory\ClassFactory())->createImage(
	Imagine\Factory\ClassFactoryInterface::HANDLE_GD, 
	$gd_resource, 
	new Imagine\Image\Palette\RGB(), 
	new Imagine\Image\Metadata\MetadataBag(),
);

@jcogs-design
Copy link
Author

Hi - that's super helpful thanks.
Am just getting head around Imagine and finding the documentation quite terse: great as a reference for specific methods, but not so useful for getting a handle on approach used by library. Such illustrative information as I have found so far dates from 2011, and not useful for current version of library.
Do you know if there are good sources of information on use of the library beyond the docs?
Thanks!

@ausi
Copy link
Contributor

ausi commented Nov 12, 2022

Do you know if there are good sources of information on use of the library beyond the docs?

I don’t know. I usually read the source code directly to find out how it is meant to be used. ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants