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?
Related
I would like to set the gif file in the featured image. I would like it to run when I hover over it with the mouse.
I know I should set this in functions.php file
Together with the code:
add_theme_support ('post-thumbnails');
Unfortunately, I have no idea how to do it. I create my blog and I have never done such things. Could someone help me how to do it?
Thank you for your help!
When you upload an animated GIF to WordPress, it does all of it’s resizing magic to make the various thumbnail sizes (defaults are thumbnail, medium and large, in addition to the original full). When it does this, the resized versions lose their animation.
If your theme displays featured images at any size other than full, you’ll thusly lose your GIF’s animation.
If you definitely know that you want to display the animated version, though, there’s a little trick you can use.
<?php $thumb_url = get_the_post_thumbnail_url();
$thumb_low = strtolower($thumb_url);
if (strpos($thumb_low, '.gif') === false) {
$thumb_size = 'large';
} else {
$thumb_size = 'full';
}
?>
What am I doing here is getting the URL of our featured image, then I make sure it’s all lower case letters (WordPress may do this anyway, but just to be safe), then I check to see if .gif is present in the thumbnail’s URL, and finally, if it is, I set the thumbnail size I use to ‘large’. Doing so will allow me to use the original image, which retains it’s animation.
Then, I just need to tell our call to the_post_thumbnail() to use the variable thumbnail size we set, like this:
the_post_thumbnail($thumb_size)
If you’ve ever tried to set an animated gif as a featured image in WordPress, you’ve probably discovered that you can’t.
The reason why is pretty simple. Your theme grabs a resized version of the featured image you upload. And in the case of an animated gif, that means it’s not grabbing the original gif image, and so you end up with a static image.
The way around this is pretty simple, however. You can just install a plugin that automatically sets the featured image from the first image in a post. Of course that means you will need to make the animated image the first image, but at least it’s a workaround.
There are a number of plugins that will let you automatically set your first image as the featured image. I tried two and the both worked: Autoset Featured Image and Automatic Featured Image Posts.
Something else I found was that I didn’t even need to download the gif. I could just insert it with the URL.
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+ulInY9jok4R2fs9KcoIWqTIwD0ZPz3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ySbfmYdANkleH5sQYUoEXGlCfK4BTzlmzv7koFsfPZcSsjf1AfEAFGe9t5bn/qb/rnbB5jqg9pcDyDQhnQxziha2oZ5Bdndh57b4zOGPEMmr+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/sPU15j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2krItu525A+eX29h7V0vgrweNKVdQ1FQ16w+ROoiH+NethMJ7P357mE582iNLwb4eXQdLAlAN5Nhpm9PRfwroaKK7SQooooAQgEYIyDXEeJvAEF8z3WkFbe4PLRHhG+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.
I am letting users preview images using URL.createObjectURL() (which represents the image as a blob). This has worked great, but now I am using the plugin jCrop to let users crop said images and I have encountered a minor issue.
jCrop has worked fine for blobs derived from jpg files and png files w/o transparency, but blobs derived from png files with transparency are rendering transparent pixels (on the canvas) as black (the same effect was happening with these images when resized and uploaded to the backend (php) but this was corrected using imagealphablending()).
jCrop is called as followed:
jQuery(function($) {
$("#myImageContainer").Jcrop({
onChange: myFunction
}, function () {
jcrop_api = this;
});
});
The "black" images on canvas are uploaded and saved properly with transparency, so this is a front end effect only. Additionally, the same effect is observed when the source png is used to preview instead of the png-derived blob. Is their any way to correct for this effect on the canvas instead of the backend?
UPDATE: The transparent image is black from the start...I am assuming the author of the plugin set the canvas background to be black. I will try and change this.
There are images displayed inside a HTML table in a PHP code :
The code of this table is :
for ($i = 0; $i < $data['list']['cnt']; $i++) {
$tabRows[$i][1]['width'] = "45%";
$tabRows[$i][1]['align'] = "center";
$tabRows[$i][1]['value'] = '<img src="'.HTTP_FIGURES.$data['list'][$i]['fig_image'].'" />';
}
As you can see the background of the images are seen and they make the page dirty. So I want to remove the background of each image. How to do that ?
Make the images a transparent PNG.
Your only practical solution is to go through each image with an image editor, delete the background and re-save as a .png with transparency.
Take any image editor like GIMP (free), Paint.net(free), Photoshop or any other image editor and add transparency where you need it. Here is a tutorial for paint.net. If your images are not in PNG - you will need to make PNG images as JPEG has no transparency.
You have 2 options:
Edit images with a image editor like paint.net and make the backgrounds transparent.
Use the PHP GD functions to 'edit' the images. This can be cumbersome, because you have to determine what color you want to replace with a background color. Often, a fixed color is used, or the color in pixel[1,1].
My advise, if there are not to many images, go for 1.
I have a gif file with many icons and buttons on it..
What I want to do is include that gif file using php gd somefunction("file.gif")
then, resize the new image to 30px by 30px.. and then be able to position (using x and y coordinates) the actual gif file, so that only a certain area of the image shows on the new file..
just like the css background-position property but, with gd.
Thanx
imagecopyresized() resizes the image, so it doesn't quite work for what I was exactly looking for.
For anyone else that might need this, the best function is actually imagecopy().
http://www.php.net/manual/en/function.imagecopy.php
It will do the trick..
Thanx Trufa for the quick answer though.
imagecopyresized()
http://www.php.net/manual/en/function.imagecopyresized.php
Should do the trick for adjusting the size.