Before|After Comparison • Source Code

With a gesture, compare two different photos processing

Before|After Comparison • Source Code

Before|After Comparison • Source Code, 5.0 out of 5 based on 2 ratings

Before|After • Comparison feature
What is it, what’s for?

Before|After is a comparison feature between two images. I originally developed this tool to allow my readers to be able to very quickly and with high efficiency, compare my photographies before and after the post-processing. This allows me to support beginners and amateurs in a logic of learning photography in a opened way. This wish is still uncommon, it is especially in contrast to nauseous methods so many people still adopt, suggesting — to the most novice and/or naive — that their photos are unedited, right from the camera, etc. A pseudo attempt at self-preservation, very ridiculous, but also human too… The function is particularly simple to use: just place the mouse cursor over the image to be compared and the function is activated immediately, thus allowing, while you ride the cursor, to compare two different states.
Now, I give free access to the source code of this tool so that more people wanting to share their work based on this principle, can easily do so.

License
“Before|After • Comparison Feature”
by Édouard Puginier is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Permissions beyond the scope of this license may be available at http://tazintosh.com/en/contact/

Creative Commons License

Demos and ideas
Details
  • Simple tool, efficient and fun
  • Compare just anything you want
  • Free
  • For personal & pro. projects
  • Cross-platform
Bibliography

Three steps install

The tool is composed as follows: the HTML code basically constituted of the two images to compare, included in a container; a CSS stylesheet; the javascript code to handle user interaction, now only available for the jQuery library, but soon for Mootools, and is possible, as standalone.

With a Creative Commons license (see above), I keep my copyright but allow people to copy and distribute my code provided they give me credit — and only on the conditions specified on the license.
You'll have to edit the “src” property of lines 2 and 3 with your own path to your images.
<div class="comparisonArea">
	<img class="afterElement" src="pathToTheAfterPicture" alt="">
	<img class="beforeElement" src="pathToTheBeforePicture" alt="">
</div>
.comparisonArea {
	display: inline-block;
	cursor: ew-resize;
	position: relative;
}

.afterElement,
.beforeElement {
	display: block;
}

.beforeElement {
	left: 0px;
	top: 0px;
	position: absolute !important;
	clip: rect(auto, 0px, auto, auto);
}
I assume you know about jQuery and have installed it for the following code to work.
More informations. Please note that at line 22, starts DOM Ready.
/* ============================================================ */
/* Before|After • Comparison Feature v1.0 — ©Édouard Puginier — http://tazintosh.com */
/* Under Creative Common license Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) */
/* ============================================================ */
function setupComparison(beforeElement) {
	var comparisonAreaElem = jQuery(beforeElement).parent();

	function comparisonStart(event) {
		var offset = jQuery(beforeElement).offset();
		var x = event.pageX - (offset.left);
		jQuery(beforeElement).css('clip', 'rect(auto,' + x + 'px, auto, auto)');
	};

	function comparisonStop(event) {
		jQuery(beforeElement).css('clip', 'rect(auto, 0px, auto, auto)');
	};

	comparisonAreaElem.mousemove(comparisonStart);
	comparisonAreaElem.mouseleave(comparisonStop);
}

jQuery(document).ready(function(){

	// Detecting available comparisons
	jQuery(".beforeElement").each(function(beforeElementIndex, beforeElement){
		setupComparison(beforeElement);
	});

});
Soon
Soon
Versions history

They're already using it!

If you too, are using this tool, let me know and I'll update this list with your name, website and twitter nickname.

Be part of it!

Want a feature?

Use the form following or post a comment at the bottom of this article to share your ideas/needs. If you post a comment, users can vote for your idea using the + and - symbols associated. Also, if you make changes to the code, thank you for sharing them by posting a comment explaining the work done, or by sending me an email.

What else?

This symbolic coffee or your comment would be a true encouragement to offer you more contents. Thanks…

Changes form:

Share or rate this article – Click to display social medias

Leave a Reply