Cannot encode multiple times?
I'm trying to convert a jpg file into a png and then encode the image into a png formatted data url.
$img = Image::make($feed->data[$i]->images->low_resolution->url);
$img->greyscale();
$img->contrast(7);
$img->gamma(2);
$img->limitColors(12, '#ff9900');
$img->resize(120,120);
$img->encode('png', 2);
array_push(
$feed_imgs,
$feed_imgs_item_arr = [
'id' => $feed->data[$i]->id,
'url' => $img->encode('data-url')->encoded
]
);
However, the first encode command seems to be skipped over when the second encode command runs.
I think explicitly defining the filetype in the 'data-url' encode command function would be awesome - ie:
$img = Image::make('/images/test.jpg');
$jpg_to_png_data_url = $img->encode('data-url/png')->encoded;
Yes, data-url is currently always in png format. Explicitly defining the filetype sounds like a good idea. I will add it in the next version.
Btw. you can run encode() and cast the object to string to get the encoded data, without accessing the property.
// encode png data-url
$encoded = (string) $img->encode('data-url');
Thanks, btw I was looking through the source code and I did see that the default data-url filetype is PNG, however, I am getting the following at the start of the default data-url data that's outputted:
'data:image/jpeg;base64'...
That's not a PNG, is it? Is it outputting as a jpeg filetype because the input image file is a JPG? If that's so, is it not feasible then to convert an image to a different filetype before encoding it as a data-url?
Thanks for the cast to string tip (don't know why it didn't cross my mind) , i was messing around with the object...