Categories
Articles

Three Steps to Instantly Remove The Background From Your Images


By Lon Hosford
I really hate using powerful graphic programs to do simple tasks in artwork workflow. One specific workflow task is removing backgrounds from images.

Example using Woman's Face. Example using Woman's Face
Example using Woman’s Face.
Source: https://clippingmagic.com
Often these are hurried photos taken wrenching the smartphone from its case or purse and snapping a shot. It is also the typical case purchased artwork or even free artwork.

You need to bring up that nasty Photoshop or Fireworks, bogging down your computer resources, requiring an original bloated file, dealing with layers, tolerances, masks, fettering, anti-aliasing and many trial and error steps to just remove artwork backgrounds. In most cases the original is the artwork without the background. And that is what I want to move along to the next task in artwork development.

I crossed a SAS (Software as a Service) website Clipping Magic. It is free first to note. Second there is no signup needed. It has one targeted goal. That is to “Instantly Remove The Background From Your Images”.

[ad name=”Google Adsense”]

Just Three Minus One Steps

There are three steps, well actually two steps.

1. “Drag your image onto the drop-zone above, or choose a file using the button.” Yes literally when their website loads you drag your image into the target drop zone. No signup or hassles.

Example Watering Pot Original.  Source: https://clippingmagic.com
Example Watering Pot Original.
Source: https://clippingmagic.com

2. “Mark some foreground green and some background red and the algorithm takes care of the details.” The spacebar worked in Safari for me to toggle red and green.

Example Watering Pot Selected. Source: https://clippingmagic.com
Example Watering Pot Original.
Source: https://clippingmagic.com

[ad name=”Pearson Web Dev Books”]

3. “The background is removed by adding an alpha channel, with a suitably feathered boundary.” In addition to the default transparent background you can choose a solid background from a pallet, a color chooser or enter a color hex value.

Example Watering Pot Complete.  Source: https://clippingmagic.com
Example Watering Pot Original.
Source: https://clippingmagic.com

Other features in the tool include zooming, adjusting the sensitivity of the tool. You download and it will suffix the file name with clipped_rev_1.png, upping the digit for each revision.


Categories
Articles Tutorial

Mobile First Responsive Design with Media Queries Overview


Part 1 of 5 | Next

By Lon Hosford
Designing for mobile first is very easy if you have a single column of text and add the CSS img {height: auto; width: 100%; } to make the images flexible. But ultimately you design multiple column layouts and graphics that may not be suitable for dynamic resizing across the wide width spectrum of viewing screens that your visitor may be using. Blog image for CSS Media Query 101 Mobile First Tutorial OverviewIn particular for smaller devices you really do not want to exceed the device width. More importantly you do not want the device web browser scaling your fine layout and design into something hard to appreciate and even to read.

Responsive Web Page Design
To handle different viewing widths and device web browser defaults you are introduced to responsive web design.
Responsive design can be a very confusing subject with various approaches, techniques and even interpretations as to what it means. One dimension is designing different experiences for different target viewing devices but achieving the same content and action goals of the web page visit. Wow that is a lot when you figure the hundreds of viewing devices around. The other dimension is the implementation on the technical plain in HTML and CSS and is the main focus of these articles.

Mobile First Responsive Design Demo
[iframe https://www.youtube.com/embed/8CFfFDxMSR0 640 360]

Source Files for the video series: Download

Responsive Design Approach Filtering

On the technical side there are many approaches using HTML and CSS. A lot depends on design and what you can capitalize based on the features of the target devices such as aspect ratio, resolution, color, width and height to name a few. That is a lot of variables to design around when you consider the number of devices, their differences and even a simple feature of screen orientation. So you need to know when anyone of those has merit for detection and thus a design change to take advantage. For example a higher resolution might offer showing a better quality video or image.

So you need to filter and have a base point. With that in mind, one feature that transcends across all of these choices is device viewport widths. Designing for device viewport widths makes a great base point for simplicity of design and of implementation.

Designing for the Smallest Targeted Viewport Width

This series of articles presents one approach that focuses on planning for device widths and designing for the smallest width first. We can call this the mobile first approach. But it really designing for the smallest targeted viewport width. I will explore the viewport in one article, but the viewport is basically what you see if you position a window on your computer partially offscreen. You could say the smallest viewport width is one pixel, but really it is more what you want to put your time and effort into designing. Rather you need to be more selective about the target design viewport widths.

Dealing with the Endpoint Viewport Widths

You are going to have to think about the viewport width below your smallest target and the viewport width above the largest. Generally for the smallest viewport width you have a single column flexible layout using the smallest fonts that present text in a reasonable manner and images that are resized. I like to call that the base. I should be able to see the base from a small width to the largest width monitor resolution I can find. At the extremes it may not be very aesthetic, but it does allow content consumption.

ed2go

For the largest target viewport width you are going to cap the content width.

Finally you are going to have two or three or more if you want to work harder, target viewport widths to make a design. In between those targets, your design is likely to be flexible. The target viewport widths are also called breakpoints.

[ad name=”Google Adsense”]
For example you may have the first viewport width set at 320 pixels, the second at 768 pixels, the third at 1024 pixels. You design for each needs to be flexible up to the next breakpoint. That handles the variety of devices between the breakpoints. The final breakpoint will work the same but it has a limit. The first breakpoint you could also specify a minimum scaling limit, but I would recommend you target the smallest width to simplify your work.

This series assumes you are new to responsible design using CSS but have a general experience with CSS that you can recognize it and query the Internet for additional learning as you need it. If not here are some resources that I have found helpful:

[ad name=”Pearson Web Dev Books”]

Project File Review
We will use a paired down HTML and CSS file for this series. This video reviews what is already set up.

[iframe https://www.youtube.com/embed/Glh4eGcMaRI 640 360]

Source Files for the video series: Download


Categories
Articles

JQuery Ajax PHP Dynamic Content Loading


By Lon Hosford
This example shows how to dynamically load HTML content from PHP into an HTML element using JQuery and AJAX.jq_php_logos_900_544

You might want to do this when the main page content has all the needed SEO material but there is a lot of additional content such as course or code files that can be loaded on visitor demand. For example a course page or tutorial page where you have all the summary and details about the course or tutorial that would satisfy SEO. Then you can have the user load the particular items they want.

This example provides the basic elements in JQuery, HTML, AJAX and PHP for a potential architecture to do that and then build upon further.

[ad name=”Google Adsense”]

Source Files: Download

[iframe https://www.youtube.com/embed/GhDZpphiDII 640 360]

The User Interface

This example has three buttons.

UI Before Buttons Are Clicked

Two are for loading content and one for clearing so we can play a bit while testing. Do not expect the user will need to clear the data.

UI After  Buttons Are Clicked

The User Interface Code

The first file to look at is the HTML document.

Full listing of ui_view_content.php

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="ajax.js">
</script><link rel="stylesheet" type="text/css" href="site.css">
<title>JQ Dynamic Load Content | lonhosford.com</title>
<script>
	$(document).ready(function(e) {
        // Click handler for content_button class
		$(".content-button").click(function(e) {
            //console.log(".content-button.click");
            //console.log($(this).attr("data-content-id"));
			contentId = $(this).attr("data-content-id");
			sendServiceRequest(
				"content-id=" + contentId,
				function(data, status){
					//console.log("SUCCESS!");
					//console.log(contentId);
					//console.log(data);
					ele = "#" + contentId;
					$(ele).html(data);
				},
				function(data, status, error){
					//console.log("FAIL!");				
				});			
        });
		 // Click handler clear button
		$("#clear-content-button").click(function(e) {
			//console.log("#clear-content_button.click");
			$(".content").html("");
		});
   });
</script>
</head>
<body>
<div id ="wrapper">
    <header>
		<h2>JQ Dynamic Load Content</h2>
    </header>
    <div>
        <p><input id="clear-content-button" type="button" value="Clear All"></p>
        <div>
            <p><input class="content-button" type="button" data-content-id="content01" value="Load 1"></p>
			<p id="content01" class="content"></p>
		</div>
        <div>
            <p><input class="content-button" type="button" data-content-id="content02" value="Load 2"></p>
     		<p id="content02" class="content"></p>
		</div>
    </div>
</div>
</body>
</html>

Examine lines 45 and 49. You see they share the class attribute content-button.

            <p><input class="content-button" type="button" data-content-id="content01" value="Load 1"></p>
			<p id="content01" class="content"></p>
		</div>
        <div>
            <p><input class="content-button" type="button" data-content-id="content02" value="Load2"></p> 

We have on line 12 the JQuery click method calling a function for the content-button class. So both buttons call this same function when clicked.

	$(document).ready(function(e) {
        // Click handler for content_button class
		$(".content-button").click(function(e) {

Lines 45 and 49 are using the element attribute data-content-id. The values of the data-content-id are content01 and content02 respectively.

            <p><input class="content-button" type="button" data-content-id="content01" value="Load 1"></p>
			<p id="content01" class="content"></p>
		</div>
        <div>
            <p><input class="content-button" type="button" data-content-id="content02" value="Load2"></p> 

On line 15 we extract the data-content-id values and they are then sent on to PHP to return the needed content. All that is handled in the external ajax.js file we will look at when we get to the ajax.js code listing.

	$(document).ready(function(e) {
        // Click handler for content_button class
		$(".content-button").click(function(e) {
            //console.log(".content-button.click");
            //console.log($(this).attr("data-content-id"));
			contentId = $(this).attr("data-content-id");
			sendServiceRequest(
				"content-id=" + contentId,
				function(data, status){
					//console.log("SUCCESS!");
					//console.log(contentId);
					//console.log(data);
					ele = "#" + contentId;
					$(ele).html(data);
				},
				function(data, status, error){
					//console.log("FAIL!");				
				});			
        });

The ajax.js has a sendServiceRequest function which accepts a NVP (Name Value Pair). The server is expecting the name to be content-id.

Its second argument is the call back function for successful network send and receive. The third argument is if something horribly goes wrong on the network or the server and it is either not reached, never responds or it returns unexpected data formats. The data format returned is simple text containing HTML markup.

In the success function starting on line 18 we take the contentId variable that is available via closure and prepend the hash character on line 22 to create an id for JQuery to find. We thus get the same values for the two button data-content-id attributes which will be content01 and content02. On line 23 we call the JQuery html function to replace the content of the element having that id.

Lines 46 and 50 have the two possible elements with the ids of content01 and content02.

            <p><input class="content-button" type="button" data-content-id="content01" value="Load 1"></p>
			<p id="content01" class="content"></p>
		</div>
        <div>
            <p><input class="content-button" type="button" data-content-id="content02" value="Load 2"></p>
     		<p id="content02" class="content"></p>

So they are updated in line the Javascript on line 18.

Then so we can play a bit a clear button was added on line 43.

        <p><input id="clear-content-button" type="button" value="Clear All"></p>

And the click handler is on line 30. On line 32 all elements with the class attribute value of content have their HTML removed.

		 // Click handler clear button
		$("#clear-content-button").click(function(e) {
			console.log("#clear-content_button.click");
			$(".content").html("");
		});

And the two elements are the same we are loading from the server seen here on lines 46 and 50.

        <div>
            <p><input class="content-button" type="button" data-content-id="content01" value="Load 1"></p>
			<p id="content01" class="content"></p>
		</div>
        <div>
            <p><input class="content-button" type="button" data-content-id="content02" value="Load 2"></p>
     		<p id="content02" class="content"></p>
		</div>

The article is not about styling so you see it is simple and designed to fit this blog width.

These are the CSS files if you need to explore. The site.css file has the style selectors particular to the web page. We first import the Meyer reset.css to create the basic uniform styling to build up.

You could get more elegant with JQuery how the content opens with saw a collapsible approach making the buttons full width and having them slide the content down once it is loaded.

site.css

/* Meyer CSS Reset */
@import 'reset.css';
body{
	font-family:"Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif
	}
div{
	padding: 5px;	
}
header > h2 {
	font-size:2em;
	text-align:center;}
/* Content container */
#wrapper{
	margin:0 auto;
	width:590px;
}
/* Content containers */
.content{
	border:solid 1px; #000000;
	height:70px;
	margin-bottom:5px;
	min-height:25px;
	overflow:auto;
	padding:7px;
}

reset.css

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}

[ad name=”Google Adsense”]

Client Side Network Handling

Nothing particularly special about using the JQuery ajax method. It is just modified to sent a NVP, receive HTML and call a success or fail function.

The ajax.js file has the sendServiceRequest generic function makes on lines 5 to 10 an ajax call to the get_content.php script. It passes in its nvpSendData parameter to the get_content.php script using POST and expects and HTML return.

Lines 11 to 16 have the successful network handler which simply called the passed in function reference.

Same for the network failure on lines 17 to 22.

ajax.js

// Generic AJAX call to POST NVP formatted data to server PHP and receive HTML
function sendServiceRequest(nvpSendData, successCallback, failCallBack){
	//console.log("sendServiceRequest");
	//console.log(JSON.stringify(nvpSendData));
	$.ajax({
		type: "POST",
		url: "get_content.php",
		data : nvpSendData,
		dataType : 'html'
	})
	.success(function(data, status){
		//console.log(".done");
		//console.log("success data: " + JSON.stringify(data));
		//console.log("Return AJAX status: " + status);
		successCallback(data, status);
	})
	.fail(function(data, status, error) {
		//console.log(".fail");
		//console.log("Return data: " + JSON.stringify(data));
		//console.log("Return AJAX status: " + status);
		failCallBack(data, status, error);	
	}); 
}
Server Side Network Response

The first file is a stripped down controller for PHP that only returns HTML. You see the headers on lines 10 through 13 which are depending on how you want caching handled.

Line 17 sanitizes the POST content-id value we are receiving and places it into the $content_id variable. If the sanitzing fails then $content_id is false and we are returning a paragraph with a hard space on line 23. This is all we need for the demo. We could also return nothing.

If the $content_id variable is a string then we include the content.inc.php file.

get_content.php

<?php
/**
 *  Process network data received and return html content matching content-id.
 *  @author Lon Hosford 
 *  @link www.lonhosford.com 
*/
/**
 *  Standard headers to avoid caching
*/
	header('Cache-Control: no-cache, must-revalidate');
	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
	header('Pragma: no-cache'); // HTTP 1.0.
	header('Expires: 0'); // Proxies.	
/**
 *  Validate and capture content-id 
*/
$content_id = filter_var($_POST['content-id'], FILTER_SANITIZE_STRING);
/**
 *  Return content based on content-id
*/
// Invalid content-id format received
if ($content_id == false){
	echo '<p>&nbsp;</p>';
// Valid content-id format received
}else{
	include_once "content.inc.php";
}
?>

The content.inc.php file is designed to return to standard out. It uses a switch statement to choose the $content_id variable on l one 7 which has the value passed in from the client. Lines 8 and and 11 have the corresponding content to return. Line 13 handles an invalid $content_id value.

There are many ways to return HTML from the server with PHP including storing it in a database. So you can do as you wish and even use another data format such as JSON or XML for the standard in and standard out.

content.inc.php

<?php
/**
 *  Std-out html content matching content-id from client.
 *  @author Lon Hosford 
 *  @link www.lonhosford.com 
*/
switch ($content_id){?>
<?php case 'content01':?>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut <strong>laoreet dolore magna aliquam</strong> erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. </p>
	
<?php break;case 'content02':?>
<p>Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.</p>
<?php break;default:?>
	
<p>&nbsp;</p>
	
<?php break;
}?>

[ad name=”Google Adsense”]


Categories
Articles

Best 3 Personal LAMP Web Servers


By Lon Hosford
Static web pages can be loaded from your local hard drive and viewed in a web browser.

xampp wamp mamp logosHowever to send and receive data from a web server such as in processing a form, you need to place your files on a web server. Actually you might find some plugins that require user authentication may require an http web browser address line. Placing your files on a web server allows you to test exactly using http urls and to use a server database.

However using a public web server like BlueHost is just that public. Generally this is your production version of your web site and you do not want to be experimenting with changes that could render your site unusable. You could create a practice domain and host it but still you have the inconvenience of having to FTP your file changes to the server each change you make. It is more convenient to see the changes as soon as you save them without the step to move them to the web server.

For beginners all you need is a private web server. When you are ready to go live, then you need a public web server such as BlueHost.

Popular web servers are called the LAMP stack or Linux web hosting. LAMP stands for Linux (Operating System), Apache, MySQL and PHP. You can install the AMP part of LAMP on most computers. They are generally intended for local development work and not for public web hosting. But security and performance is constantly improved making them useful for in house web servers. Here are popular free versions.

XAMPP (Windows, Mac, Linux and Solaris)
xampp logo
XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. It has versions for Windows, MacOS Solaris and Linux. XAMPP is really very easy to install and to use – just download, extract and start. Free of Charge. It comes with PHPMyAdmin and ProFTPD.

MAMP (Mac OS only)
mamp logo
MAMP installs a local server environment in a matter of seconds on your Mac OS X computer, be it MacBook or iMac. MAMP is free of charge however there is a PRO version that has a fee.

WampServer
wampp logo
WampServer is a Windows web development environment. It allows you to create web applications with Apache2, PHP and a MySQL database. Alongside, PhpMyAdmin allows you to manage easily your databases.

[ad name=”Google Adsense”]