Wednesday, March 9, 2016

Parallax Burns: Converting Photographs from 2D to 3D with SVG

Last week we talked about ZorroSVG, a tool for converting your chunky transparent PNG-32s into slim and flexible SVGs.

That got me thinking.

A few weeks earlier, I talked about the use of the Ken Burns effect in film and television.

[caption id="attachment_126366" align="alignright" width="334"]GIF animation. Camera zooms in and out on an archive photo of President Wilson at the Baseball. Figure 1: The 'Parallax Ken Burns' effect (as a GIF)[/caption]

But there’s another similar, but slightly more sophisticated technique that pans and/or zooms different layers of a photograph at different rates to give the image a slightly 3D effect. Sometimes this is called a ‘Parallax-Ken Burns effect’, other times ‘The 2D to 3D Effect’, sometimes it’s the ‘2.5D Effect’. You might think of it as the ‘History Channel effect’ but it could just as easily be the ‘VH1: Behind the Music effect’.

This is a classic videographers trick, so all the tutorials you’ll find on Youtube for this effect are aimed at Adobe After Effects users.

But what if we could mimic the effect entirely inside a standalone SVG graphic?

That was the plan.

It didn’t quite work out that way (yet) but I thought it might be useful to share what I have so far. Let me be clear: this is a jumping-off point for people, rather than a finished production-ready product. I know it doesn't work in Opera 3. ;)

I don’t want to get super code-heavy here, but you should be able to pick through the CodePen to understand the detail.

The plan was to…

  1. Break down a photograph into three overlapping layers – front, middle, and background.
  2. Convert those layers into SVGs using ZorroSVG.
  3. Manually re-combine those layers into a single multi-layered SVG
  4. To use CSS animation inside that SVG to get the Parallax-Burns effect.

First take

The Photograph

[caption id="attachment_126371" align="alignright" width="400"]Woodrow Wilson archive image Figure 2: Woodrow Wilson archive image[/caption]

My first task was to find a good image to work with. I found this nice copyright-free archive photo of Woodrow Wilson from Flickr (fig 2) that has a good sense of depth to it.

After dropping it into Photoshop, I repaired the damage in the bottom half and then split it into three separate layers (all PNG-32s):

  1. Foreground: The fence in the foreground
  2. Middle ground: Wilson and his fellow VIPs
  3. Background: The remainder of the grandstand

As we’re going to be moving these layers in relation to each other, we’ll need to create some extra image to fill the gaps. I used Photoshop’s ‘content-aware fill’ to clone in new image behind the fence and also behind Wilson and co. It’s pretty rough but it will do.

Broken in three layers

Now we have our raw image components.

The SVG Markup

CodePen allows you to write SVG markup straight into the HTML panel so it’s a great place to play with SVG ideas. Let’s go straight to my first ‘proof of concept’ test:

See the Pen SVG Parallax Burns by Alex (@alexmwalker) on CodePen.

You’ll notice that the fence layer moves farther and faster than the middle layer as it’s closer to us. That's the key to the parallax effect.

In SVG, there are two ways to put pixel-based images into your file – and it’s really no different to HTML in that regard.

Method 1. Encode & embed your pixels:

zorro-preview

You can base-64 encode your pixels. This just turns your image into a long string of numbers and letters that you can paste into your SVG document in any text editor. This is precisely what ZorroSVG does and if you open a ZorroSVG file in a code editor you’ll see something like this:

Encoded images are a little unwieldy to work with, but it’s worth it to be able to encapsulate everything in a single, standalone file. This work break if you download it, or move it to another folder, or lose your internet connection.

Method 2. Link your pixels via URL:

As we commonly do with our HTML, it’s possible to link to an external image from inside your SVG like this.

[code language="html"]
<image class="back"
xlink:href="http://ift.tt/1RAPd7a"
x="0" y="0"
width="970" height="690">
</image>

[/code]

This is neat and easy-to-work-with, but if your SVG and image resources get moved or separated somehow, your SVG will have sad 'missing image' flags in it. I don’t like that idea.

Nevertheless that’s exactly what I’m doing in the CodePen test above. The three IMAGE elements are stacked back to front. We’ve given each IMAGE element a sensible CSS classname too – .front, .mid and .back.

I’m not going to explain every line of code but the noteworthy parts include:

  • Inside the STYLE tags at the top of the SVG, you’ll see two simple CSS scaling animations - parallax-front and parallax-mid.
  • I’m getting a bit fancy by adding an SVG blur filter (filter:url(#effect-1); ) to the front and back layers, but leaving Wilson’s layer sharp to increase the depth. Ideally, I’d love to slowly dial-up that blur effect as we zoom in to increase the 3D feel. But not for this demo.
  • The ‘transform-origin’ property of 50% 50% means we will be scale/zooming into the exact center of our image. A value of 50% 100% would feel like we were moving in-and-under Wilson. A value of 50% 0% would feel like we were zooming over his head.

As a test, I think this is very successful. There’s a real sense of time and space that isn’t present in the original photo. But on the down-side, the SVG relies heavily on external files that may not always be available. Things would be much more robust if we could sink it all into a single, standalone file.

Continue reading %Parallax Burns: Converting Photographs from 2D to 3D with SVG%


by Alex Walker via SitePoint

Protect Yourself and Your Business from Social Engineering

IT security isn’t just about protection from digital threats. One of the most commonly overlooked aspects of security is protection from social engineering – the art of manipulating people into disclosing sensitive information. In fact, these attacks often are more dangerous than traditional threats, since they often go unnoticed and provide the malicious person with […]

Continue reading %Protect Yourself and Your Business from Social Engineering%


by Charles Costa via SitePoint

Quick Tip: Build a Video Player Component in React

This article was peer reviewed by Craig Bilner. Thanks to all of SitePoint's peer reviewers for making SitePoint content the best it can be!

In this quick tip, we're going to create a React video component. This will enable you to define a list of videos and allow your visitors to cycle between them. The component will support Vimeo, YouTube and Dailymotion but you can easily extend it to support other video providers.

[author_more]

By way of a dev environment we'll use react-hot-boilerplate which comes with hot reloading enabled. This means we can build our component and see the results immediately in the browser, without refreshing the page every time the code changes.

You can find the source code on our GitHub repo, as well as a demo at the bottom of the article.

Starting from a Boilerplate

We'll start by setting up our working environment from a boilerplate. Assuming you have git installed on your machine, let's clone the repo by running:

git clone http://ift.tt/1ziTu6g

This will create a folder react-hot-boilerplate in the directory we're at. Let's now navigate to that folder and install dependencies by running:

cd react-hot-boilerplate
npm install

Next, we'll need to install querystring which we'll be using later on.

npm install --save query-string

Finally, we can kick things off with:

npm start

If things have gone according to plan, the message Listening at localhost:3000 will appear in the prompt. Webpack will still need to process the files before being able to serve them. After some delay, a sequence of operations should appear in the prompt, ending with webpack: bundle is now VALID, which means everything is ready to go.

By navigating to http://localhost:3000/ in the browser you should now be able to see 'Hello, world.' displayed.

Creating the Component

The first thing to do is to create the component file at src/social-video.js. For now the minimal code needed for the component to work and some dummy render content will suffice.

import React, {Component} from 'react';

export default class SocialVideo extends Component {
  render() {
    return (
      <h1>Social Video</h1>
    );
  }
}

Continue reading %Quick Tip: Build a Video Player Component in React%


by Bruno Mota via SitePoint

Products Comparison Table with CSS and jQuery

A responsive table to compare and filter through multiple products by using css and jQuery. A time-saver comparison table, specifically designed for big online stores.


by via jQuery-Plugins.net RSS Feed

Creating a Hello Bar with WordPress

Email lists are powerful. In a world crowded with a plethora of social networks, from Facebook to Snapchat, email is still one of the most powerful marketing channels.

Giants like Kissmetrics, Buffer, Michael Hyatt, and Jeff Goins agree that building and marketing to an email list is one of the best moves you can make for your brand. But actually doing that is much easier said than done. If you’ve tried to collect emails from your site, you know how slow of a process it can be.

You might have heard of Hello Bar. It creates a thin bar at the top of your site that spans the screen’s length. Readers can conveniently enter their email into the opt-in box.

Hello Bar

It sounds simple, and it is, but that’s why it works. If you use the Hello Bar right, you can get a jaw-dropping amount of emails. The numbers are crazy, Derek Halpern at DIYThemes got 1,180 emails in a month (He posted more about it on Social Triggers).

The only downside is the click limit for free users. If you use the free Hello Bar, you’ll have a 100-click limit on your bar. That means you won’t be able to collect 101 emails without upgrading. There’s also a watermark that doesn’t go away without a Pro plan. While their paid plans are reasonably priced, you don’t need to upgrade because you can build your own Hello Bar for free.

With a little basic WordPress manipulation, you can create your very own Hello Bar clone. Those giants I linked to earlier don’t necessarily love Hello Bar, they love the Hello Bar concept. And you can build that same concept for absolutely no cost. You can also integrate it with your email marketing service. I’ll be showing you how to integrate it with MailChimp.

If you’re a WordPress novice, fear not––all you have to do is install a couple of plugins and change some settings. It’s that simple, and the result is a nice, appealing top bar in the Hello Bar style that you can modify to your heart’s content.

And for those who favor more versatility in the way of coding, we’ll also go over how to code a bar from scratch. But even that’s not complicated.

So if you’re ready, let’s get started.

Continue reading %Creating a Hello Bar with WordPress%


by Ian Chandler via SitePoint

Cleaning Up a CSS Codebase

You have just been onboarded to an existing project to replace a departing developer. Or maybe you just opened that old project of yours from a few years ago. You are faced with dread and horror when looking at the code. You can do only one thing: Clean up this mess! Does that sound familiar to you? Of course it does, we all encounter this at some point or the other.

You know that cleaning up a CSS codebase is going to be a tremendous task. There are so many things to do, yet so little time – especially when the client/boss/colleague advocates the good ol’ “don’t fix what’s not broken” adage. You don’t really know where to start!

Well you’re in luck because I’ve done my share of CSS clean-ups and I’m here to give you some hints to get started with this. It’s all about grabbing the low hanging fruit.

[author_more]

Lint the Hell Out of It

In this section, I will assume your codebase uses Sass. Not only because it’s a reasonable assumption nowadays, but also because I’ve noticed poor usage of Sass is often partially responsible for a messy codebase. Still, this article might be relevant to you even if you don’t use a preprocessor, so bear with me please.

The first thing I like to do when I need to take over a codebase is lint it. Linting is the process of running a program that looks for potential errors and bad practices. I believe making the code clean is the first step towards making the code good. Here is an insightful Stack Overflow thread about the etymology of the word “lint”.

Sass has a Ruby-based linter called SCSS-Lint. You can configure it yourself or grab the recommended configuration file from Sass-Guidelines to get started right away. There is also a Node.js version called Sass-lint, although they are not 100% inter-operable, so your mileage may vary.

Try running SCSS-Lint on your Sass folder to check for errors. Chances are high that you’ll get overwhelmed with a wall of errors. This is usually the time where you’ll be tempted to give up. But bear with me! At this point, you can either try to make your linting file a bit less strict in regard to rules you don’t really care about (like color format) or you can tackle the beast up front and lint the hell out of it!

Fixing Linting Errors Found

It’s time to fix what needs to be fixed. There are two ways of doing this. The first is to go through files one by one and update what seems wrong and/or odd, such as bad naming conventions, overly-deep-nested selectors, poorly formatted code, etc. The second (and my favourite) one is to start with a bit of search and replace. I don’t know about you but I love regular expressions, so it’s always quite fun when I have to do this.

For instance, let’s say you want to add the missing leading zero in front of all the floating-point numbers (i.e. a numeric value between 0 and 1) — the LeadingZero rule from SCSS-lint. You can search for \s+\.(\d+) (all numbers following a space and a dot) and replace it with \ 0.$1 (a space, a zero, a dot, and the found number). Or if you want to honor the BorderZero rule for SCSS-lint, you can replace border: none with border: 0 in your IDE. Simple as pie!

I recently started the scss-lint-regex repository on GitHub to gather these regular expressions in one place. Be sure to have a look if you are struggling with linting a large project. Also beware with search and replace as it sometimes has unexpected side effects. After each replacement, be sure to perform a git diff to check what has been updated so you can make sure that you did not introduce a bug.

Once you’re done with transversal editing, you won’t escape the manual file crawling to clean everything that needs to be cleaned (poor indentation, missing or extra empty lines, missing spaces, etc.). It takes a lot of time, but it will help a lot for the next step, so it’s important to start with that.

Continue reading %Cleaning Up a CSS Codebase%


by Hugo Giraudel via SitePoint

Your First Drupal 8 Migration

Migrate is one of the most established modules in the Drupal ecosystem. So much so that with Drupal 8, a decision has been made to get some of its functionality ported and added to Drupal core. An important reason was that the traditional upgrade between major releases was replaced with a migration of Drupal 6 […]

Continue reading %Your First Drupal 8 Migration%


by Daniel Sipos via SitePoint