file_get_contents to image and change quality
I have some code that download开发者_高级运维s an image from a remote server
$data = file_get_contents("$rURL");
I want to then change the quality of this image, but do not want to save it out to a file first, how do I convert $data into an image that I can then use in imagecopyresampled?
Thanks
Try
imagecreatefromstring
— Create a new image from the image stream in the string
Example from PHP manual:
$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data);
$im = imagecreatefromstring($data);
As an alternative use any of the imagecreatefrom*
functions if you know the image format in advance to load the URL directly, e.g.
imagecreatefrompng('http://example.com/image.png')
精彩评论