How to convert data:image/webp,base64 in expo (or php) - php

So I have this problem where I'm receiving a webp,base64 image format from an api, The image does not show in ios devices but it appears in Android. So is there a solution for those who use expo and want to display webp images on ios?
And I can take another solution if it works in php since that is what I'm using as a backend.
an example of the returned string of the image
https://i.stack.imgur.com/k1yHv.png

Normally webp images are not compatible with Safari. You can check the compatibility for webp here.
What you would need to do is maybe use a service that converts the image to a working format, be it jpeg or png and use a <picture> tag. This is just an example of how to use the tag.
<picture>
<source srcset="images/logo#1x.webp" type="image/webp">
<source srcset="images/logo#1x.png" type="image/png">
<img src="images/logo#1x.png" alt="Logo">
</picture>
UPDATE
The above example was just to show you how to use the picture tag with different types of images.
As for the base64 images you could do something like this:
<picture>
<source srcset="data:image/webp;base64,UklGRlAIAABXRUJQVlA4IEQIAADQJACdASp+AH4APrFInUmnJCMhMXX8qOAWCWYAzb8cfTdXBy5F/Zz8xxC6HLaHpz3DPmV84d5OXdQ/aP854a+OL4BubX158GjTsd4ATr92rmvq3p43/Y82n1kj6wv3/Vk3gOKXh/1H/Z+6V9sps7nNgfOA82ktkJO4nWXR/P0q1RbEZE/vsMgdJcOWwOekhEeHUqflUSTfD9EZmzNULms1ckdpLkGpn6xhoO3q6f2pk9mzCyL5Tl8eY0ScJ4i8IzaRJiJ2ZXIHkmbAYYG+WBNYvqfv3VseUlcQNhpxkwDnEp7voFO1u0bYMpwfrYwdzct+RoQOyRxgNMHphyYihdHwH785KELmkS8ULOiM3ibN6sW1FS0Pbhfy60HfdnxEgtsxayBY0U5yPOe0B9UVGAAA/vgT2I1LG4MsV4JcMEIyUMq8dpVBkb5kgLI9Qhv2rQUyKrf6i8k0Cjf02d0+vXvTYO9sCG+g4ssg6G/Sbt24XbH1dNTFexwGmteRzhtNCGGXWhHClYYoeK+ulInY9jok4R2fs9KcoIWqTIwD0ZPz3g2QAlU/MaChNj3i9cEJEnxL+uwt6HmOoVYSZtKw/hlX2VProHuVAGq9V+20yqKL7k8HE9AJnxUVlOH9ve8y8F89JTPF27j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dndh57b4zOGPEMmr+zRCdg+EoAAAA" type="image/webp">
<source srcset="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gNjAK/9sAQwANCQoLCggNCwoLDg4NDxMgFRMSEhMnHB4XIC4pMTAuKS0sMzpKPjM2RjcsLUBXQUZMTlJTUjI+WmFaUGBKUVJP/9sAQwEODg4TERMmFRUmTzUtNU9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09P/8AAEQgAfgB+AwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A72iiisjUKKrX99badaPdXkqxRIOSe/sPU15jrvjDU9fuDYaOksUDnaFjH7yT6kdBTsJux22teMdI0gtG0v2i4H/LKLkj6noK4u++IOs30nlaZbx24P3Qq+Y/6jH6Vd0P4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IyDXEeJvAEF8z3WkFbe4PLRHhG+np/Ku4ooTsDVzxy01rxB4Un+y3KP5a/8sZwSuP9k/4V12meP9JugFvBJaSd9w3L+Y/wrrruztr6Ew3kEc0Z/hdc1yepfDrSbgl7KWWzY9h86/kef1rKrhqVTWS1BOUdjobXU7C8ANreQTZ7JICfyq0DnvXlep+Ab+xyyXlvIo6Z3Kf5GsCSO+tHMYumGP7kjYrleWrpItVn1R7mWAGSQPrWdea/pNkD9p1C3Uj+EPuP5CvIrfTb7UXC/aFJP/PR2/wrptO+G11cqHudRhjTv5aFj+uKccuivikL2z6Ivat8RbeMFNLtmlboJJflX8uprnYbPxF4yuhI5dogf9Y/yxJ9P/rV3ul+BdE08h3ha6lH8UxyP++RxXSoqooRFCqBgADAFdVOjTpfAiW3LcwPDfhKw0FBIB594R80zDp7KO1dDRRWgBRRRQB//9k=">
</picture>
Another option could be to use Modernizr to detect if the client's browser can use webp. You can check and build a Modernizr specifically for webp detection. Check it here.
What you would need to do if you have control over how the images are created/uploaded is to have a jpg/png and a webp version, and just use the corresponding versions as necessary. You do need to have both, because as I said before webp is still not compatible with every browser.
If you run the snippet you'll see that if you try to download the image it will use the webp version. If you open it from Safari it would download the jpg version.
UPDATE 2: Image conversion
As for the image conversion, what you could do is either make an image generating function that receives a webp image as a parameter and returns a jpg image.
Since you receive the image in a base64 format, you could use this topic to save the image on your server, but in a .webp format in your case. Afterwards you could use the imagecreatefromwebp() function to create a new image. Check the example at the end of that page. It converts a webp image to a jpeg.
From what I see you could do something like:
Get your API call that contains information on the image.
Check if your image exists on your server (the ideal is to create a specific folder and use the same image name).
If it exists, you return the path to the image.
If it doesn't exist, you create a .webp file from the base64 data. Then you convert it to a .jpg or a .png file depending on your needs.
You use the local image. That might also speed up your calls.

Related

PHP::Imagick Creating a Temp FIle from A Composite Image, for displaying through <img> Tag

Is it possible to create a temp file server side for viewing an image?
I've some images & they're displayed from server but I want to have them watermarked... Found out about the Imagick Class, used composite... It can be viewed when sent as header but I need it somehow visible for the tag.
I don't want to uses 'write image' & create a new image from the composited image. I'm trying to use it as client Side thing (I'm not familiar with JS... Yes, I'll look into it but need an alternative till then).
Another alternative that I'm aware of is I should control that WHILE uploading the images but I've already uploaded quite a few so...
Any help appreciated!
Have you tried using the function that generates your image as a src attribute for the <img /> tag?
I don't know exactly how your code is, but I am thinking the end result could be something like:
<img src="data:image/jpeg;base64,<?php echo base64_encode($image_headers); ?>">
You basically output the headers inside the image src as a base64 encoded string.
What you should keep in mind is that you should adjust the image/jpeg type to the corresponding type of your image.
For example:
For JPG, JPEG files it would be image/jpeg
For PNG files it would be image/png
For WEBP files it would be image/webp
And of course the encoded string should be an image of the corresponding format.

Linking images regardless of file type

I'm building a little site at the moment and users can upload their own profile picture but obviously some users pictures will be png and some jpeg, does anyone know anyway to be able to accept both when using the images as a background image in css. Here is my HTML:
<div class='avatar' style='background-image: url('users/avatars/$username.jpg')'></div>
Inside the users/avatars/ folder is every users profile picture named like so: "username.jpg" or "username.png".
Here is an example of my issue: http://cl.ly/image/3W311S2v0v0t
The first post loads the users profile image because it is a jpeg but the second post hasn't loaded the profile image as it is a png.
Thanks in advance.
You can do it in CSS like this:
background-image: url('users/avatars/$username.jpg'), url('users/avatars/$username.png');
If you absolutely must keep all the logic on the client side, in Javascript, you can catch the error if the image fails to load and attempt to load the other version.
For example:
<div class='avatar'>
<img src="users/avatars/$username.jpg" onerror='this.src="users/avatars/$username.png";' />
</div>
So if the JPG is not found and returns an error, the image will then load the PNG version.
If you are using PHP you can check the file extension and serve up different HTML. Here's how to read the file extension:
How to get the file extension in PHP?

how to set different image sources for different widths of the screen?

I have a question: I need to show JPG pictures, if screen width is smaller than 1024px and GIF video, if screen size is bigger.
Trick #1: There should be downloaded only one of them.
Trick #2: Can't be css background property, cos image sorce is random content of directory on server.
Trick #3: Server language is php.
If you can use JQuery to determine which image to load you can try this.
In your PHP set up the image like so:
<img data-jpg="img-url-1.jpg" data-gif="img-url-2.gif" />
The path of each image is defined in the tag as a data-attribute
Then allow your JQuery to run after the DOM loads and determine the screen size. Based on that value, set the src attribute of the <img /> to the appropriate URL.
$(function(){
if($('body').width() > 1024) { $('img').attr("src", $('img').attr("data-jpg")); }
else { $('img').attr("src", $('img').attr("data-gif")); }
});
Working Example: JSFiddle
The picture element will let you do just that (WHATWG spec).
<picture>
<source srcset="examples/images/large.gif" media="(min-width: 1024px)">
<source srcset="examples/images/default-small.jpg">
<img src="examples/images/default-small.jpg">
</picture>
As of July 2014 it's only in beta builds of browsers yet. But you can use a polyfill (i.e. some JavaScript to emulate the element in unsupported browsers): see Picturefill
Note that the img is not only a fall-back but is always needed: The source elements just provide alternative sources for the img element. For more info, see for example this guide.

Calling a gif with createimagefromgif in PHP

I've been trying to display a gif image using PHP and have not found a solution to my problem with the research I've done. I know I can display image in HTML/CSS, but I need to use php in this case.
<html>
<?php
$img = imagecreatefromgif("http://www.mysite.com/images/timer.gif");
?>
<img src="<?= $img ?>" alt="timer" />
</html>
That code resides in a php doc on my server. I can tell the code is working because an icon of a torn image displays on my site, and when I attempt to save the torn icon image to desktop, the automatic file name appears as "Resource id.html"?
I read somewhere that creating gifs with Photoshop CS5 (as I did) uses a different frame separator sequence, \x00\x21, instead of the official standard \x00\x2C. The guy then said he uses pattern "#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s" to bypass that issue but I have no idea how/where to implement that or if that is even my issue (tried a different gif from internet and had same display problem). Thoughts? Thank you.
Imagecreatefromgif() returns an image resource, which you can't use in this way.
Have your PHP script output the image data, with the correct headers (see example here http://php.net/manual/en/function.imagecreatefromgif.php).
Then you can call your script just like you would any other image:
<img src="http://www.mysite.com/images/generate_image.php" alt="timer" />

Using 'convert interlace -line' on animated .gif breaks image

Before I explain, you may want to take a quick look at my thumbnail generation code: http://pastebin.com/XAPPcUyZ
I pass several image types through this script: jpeg,jpg,gif,png
All types create a 220px wide thumbnail like they should, the problem arrises when the script runs into an animated .gif image - when attempting to make a thumbnail for the gif it outputs something like this: http://i.imgur.com/oh50z.gif where the image appears tiled when a proper thumbnail should look more like this: http://whatimg.com/i/mhsnf4_thumb.gif.
If I remove 'interlace -line' the animated gif's generate thumbnails without any issue, however I would like to leave this in so that the other file formats are interlaced for faster loading. Is there a way to run interlace without breaking animated gifs like this? If there isn't how can I go about detecting if a gif is animated and running a non-interlaced convert on it instead?

Categories