PhantomJS Render Page Fonts - font-face

I am using PhantomJS to take screenshots of webpages.
I have seen other posts about problems with #font-face, but the fonts on my pages are rendering correctly. The only issue I am having is that each time I take a screenshot, the fonts show slightly differently from the previous screenshot. So although they are rendering correctly, they are inconsistent in their appearance on the screenshot.
I have tried a number of fixes, most based around the assumption that it is something to do with the screenshot being taken before the page is ready, but this doesn't seem to be the issue. For example, I have delayed the screenshot being taken so that the font has time to load, and be rendered, but this doesn't solve the problem.
I have tried binding to various page events, but again, no luck.
I have attached screenshots to show the difference. The problem is, I need the rendered screenshot to be accurate in the context of what I am using it for.
As a note, I have tried CasperJS as well (knowing that it is based on PhantomJS so not expecting it to be any different).

Have you tired watching the DOM for font related events? You can also try taking a screenshot every X seconds, producing a moment-moment overview (note that this will produce a lot of empty and duplicate images. If that's a problem, try simply setting a min file size or checking to see if two files have the same size).
var page = require('webpage').create();
page.open("http://www.slashdot.org", function (status) {
phantom.exit();
});
var i = 0;
setInterval(function() {
i += 1;
page.render("/tmp/screenshots/screenshot-" + i + ".png");
}, 50);

You can delay your screenshot using the following method :
var page = new WebPage();
page.open('http://stackoverflow.com/', function (status) {
just_wait();
});
function just_wait() {
setTimeout(function() {
page.render('screenshot.png');
phantom.exit();
}, 2000);
}
Here, your screenshot is taken 2000ms after your page is loaded.
Set the delay accordingly to allow the page to completely load all resources.

Related

React native app loads url images slowly when opened the first time or when all data cleared

I have a react native app where in the home page I need to fetch the settings and then set the image as banner as per the response of settings. Until the settings is fetched, I use local image to display as banner.
My problem here is that when I install the app for the first time, after the settings are fetched it takes quite some time (3-4 seconds for the image to load, images are of some 300 kbs, they're jepeg if it matters). I tried firing onLoadStart and onLoadEnd in the Image component and logging the statements. They have quite some time lag between them. It only occurs on the first time only/or when I clear all data from settings in memory. The next time I launch the app the image seems to have only some 10s miliseconds between the onLoadStart and onLoadEnd and images show up without any delay.
SOme code snippets are:
<ImageBackground
defaultSource={require('../../assets/homebanner.jpg')}
onLoadStart={() => { console.log('loading started'); }}
onLoadEnd={() => { console.log('loaded'); this.setState({ bannerImageLoaded: true }) }}
source={this.state.settingsLoaded && this.state.bannerImageLoaded
? { uri: this.state.settings.bannerImageUrl }
: require('../../assets/homebanner.jpg')}
style={{ height: width / 2.5, width: width }} />
Here I have used defaultSource hoping that it would load before the uri image is actually loaded but this doesnt seem to make any difference. I also tried, setting a state variable bannerImageLoaded as true at the onLoadEnd event and applied logic as seen in the code.
Still, it does not make any difference and there are a blank white boxes at the very first load of the app which makes it look bad. How can I manage this??
I have heard about react-native-fast-image but dont want to use it as once the app is installed, it doesnt show any trouble the second time.
Please guide me through this.

Xamarin Forms: How to switch images without "flicker"?

[I found this question asked once before on SO about a year ago on but it went unanswered so I am asking again (wasn't sure whether best practice was to create a new question or "bump" the existing one).]
I have a Xamarin Forms application which is receiving a stream of JPEGs over HTTP and I want to keep updating a single Image placeholder with their contents. The frame rate at which I receive the images is very slow by design (maybe 5 fps at most) as this is for a time-lapse photography project. I want to be able to show the stills as an animation (think: taking a photo of a plant once per hour and then "playing" all of the stills to create a lively animation of said plant).
The problem I am having is with "flicker" while swapping one image out for the next. I've tried a variety of approaches, including having two Images (one visible at a time) and only changing the visibility once I'm done loading the latest image (I think this is maybe a naive form of double-buffering?). Have also looked into Motion JPEG, HTTP Keep-Alive, and even using a WebView (I have a valid Motion JPEG endpoint that I can read from). Anyway, nothing that I've found so far has helped reduce the flicker and therefore the "animation" of the stills remains very "jerky" for lack of a better way to put it, with a momentary blank (white) pane between stills. Frankly speaking, it looks like crap.
Here is the gist of the code which fetches the next "frame" and updates the "player" image:
var url = $"{API_BASE_URL}/{SET_ID}/{_filenames[_currentFilenameIndex]}";
var imageBytes = await Task.Run(() => _httpClient.GetByteArrayAsync(url));
var imageBytesStream = new MemoryStream(imageBytes);
var timeComponents = _filenames[_currentFilenameIndex].Split('T')[1].Split('.')[0].Split('-');
var timeText = $"{timeComponents[0]}:{timeComponents[1]}:{timeComponents[2]}";
Device.BeginInvokeOnMainThread(
() =>
{
TimePlaceholder.Text = $"{timeText} (Image {_currentFilenameIndex + 1}/{_filenames.Count})";
ImagePlaceholder.Source = ImageSource.FromStream(() => imageBytesStream);
});
Any suggestions would be greatly appreciated.

Loading images after page is completed (not lazy load)

So there is this tech blog site called "verge" :http://www.theverge.com/
When you first go there, the images are loaded after the page is completed.
(There is only the background color until the page is loaded, then the images are loaded)
How can I achieve the same thing in wordpress?
thanks
The only way is ommiting the sources until after load and then inserting them with Javascript. Browsers are very aggressive towards loading stuff as early as they can.
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="actualImage.png"/>
Be aware that an empty source generates an additional request on the document. There are several ways to work around that, one is a transparent pixel as base64 string.
document.addEventListener("DOMContentLoaded", function (e) {
var delayedImages = document.querySelectorAll("img[data-src]");
for (var i = 0; i < delayedImages.length; i++) {
delayedImages[i].src = delayedImages[i].getAttribute("data-src");
}
});
Also be aware that ommitting images that affect the flow of your page (the size of its containers) will cause the loading process look twitchy so it would be better if the images had a size set by css.
You can also just use this wordpress plugin which does exactly that (for images in the content and featured images). It also loads the visible images before the images below the fold (and optionally lazy loads those).

Click-though Image Gallery (prev/next) with multiple instances

I'm a newbie looking for help.
What I want to do is this:
I have about nine projects listed on my home page each with a large image. Each project has about five other unshown images.
I'm trying to figure out how to click on the main image and have it load the next image in its place, staying on the same page, no transition needed. I have text links to the side to also control 'next' or 'previous' images if you click on them.
I'd like the images (aside from the nine initial) to load as you need them, so I'm not loading 50 images right from the start.
I'ts also been a headache trying to make nine independent gallery/slideshows on the same page.
Right now, I'm using a bloated, messy javascript that I hacked together rto get it done, but its unstable across browsers and I feel like it has a LOT of unnecessary code. So I won't bother posting it, I think I need to start from scratch.
I feel like this should be relatively simple but I can't find any plugins or examples anywhere that do this simple task.
I'm a total amateur, but I'd love to learn how to actually code it, so if anyone knows of any tutorials out there that could help me, I would really appreciate it! I have in my head that it should just be some simple jQuery, but I'm not sure exactly how to do it.
Thanks for any help!
If you must reinvent the wheel, here is a bare bones simple example:
http://jsfiddle.net/KDnPX/
Html:
<img src="">
Previous
Next
Jquery:
var json = '{"0":"http://mw2.google.com/mw-panoramio/photos/medium/14748463.jpg",
"1":"http://mw2.google.com/mw-panoramio/photos/medium/3840183.jpg",
"2":"http://mw2.google.com/mw-panoramio/photos/medium/25214140.jpg"}';
var images = jQuery.parseJSON(json);
// load first image
$('img').attr('src', images[0]);
var currImg = 0;
$('.prevImg').click(function (){
if (currImg - 1 >= 0)
{
// show previous image
$('img').attr('src', images[currImg - 1]);
currImg--;
}
return false;
});
$('.nextImg').click(function (){
if (currImg + 1 < Object.keys(images).length)
{
// show previous image
$('img').attr('src', images[currImg + 1]);
currImg++;
}
return false;
});

Fancybox not playing nice with Cycle Plugin - Advice?

On a couple pages of mine I have a Fancybox lightbox and I have a jQuery Cycle Plugin. Normally it works fine. There are instances when I click the link that creates a lightbox then when I close it the Cycle Plugin transitions and does not come back. It makes a huge gap of space when this happens.
I am not sure what is going on, this does not happen 100% of the time. Its sporadic. I am unsure if this is a one browser issue or multiple browsers as I was able to recreate this in FF5 on two different machinces but have not replicated this in other browsers.
Any Advice?
Thanks - Here is the page: http://www.ubhape2.com/artists/ (note: any artist page has this same header and happens on all of them. The fancybox is any link referencing "Choosers")
Found out an answer to those who have similar issues (this answer came from the Fancybox forums):
After further tests, I figured out what the issue is and it happens when you open and close Fancybox quickly and successively it seems that the animation behind (jQuery cycle) is creating something called "animation queue buildup" (http://www.learningjquery.com/2009/01/quick-tip-prevent-animation-queue-buildup), which happens when interacting with other js scripts that handle animation (Fancybox uses opacity animation in the overlay).
I would say that this is not a fancybox issue and that you should bring the issue to the cycle plugin forum, however (since you are using the lite version), you may want to edit the cycle js file and do the following changes to minimize the impact of the issue (at least it won't disappear from your page):
Replace the line 166:
var fn = function() {$n.animate(opts.animIn, opts.speedIn,
opts.easeIn, cb)};
with this:
var fn = function() {$n.animate(opts.animIn, 1000, opts.easeIn, cb)};
and line 167:
$l.animate(opts.animOut, opts.speedOut, opts.easeOut, function() {
with this:
$l.animate(opts.animOut,{queue:false, duration: opts.speedOut},
opts.easeOut, function() {

Resources