jQuery – Creating a Slideshow

Lately I have been doing a lot with jQuery and one item is a slideshow. Around the web you can find a variety of slideshows, all with slightly different implementations. Well today I am going to add to the already long list with a very simple solution. With the same code you can use this slideshow to display anything you can put into html.

You can check out an example of this below or over at HyperQuake’s new site. The example just slides through a few images. I should mention that all of the contents of the slideshow is available at load, so the current implementation would probably not be the best for lots of large images. But for custom html pieces, as with the HyperQuake site, it is very nice because all the content is crawlable and therefore available to search engines for indexing.



To get things rolling we’ll take a look at the html for the pretty example above. In the code below you will see a surrounding div (id slideshow-area) which holds our slideshow content scroll area and our next and previous buttons. Inside our scroll area we have a div to hold the content and finally the content itself. As far as html goes this is pretty simple stuff.

<div id="slideshow-area">
  <div id="slideshow-scroller">
    <div id="slideshow-holder">
      <div class="slideshow-content">
        <img src="eureka_small.jpg" />
      </div>
      <div class="slideshow-content">
        <img src="wallace_gromit_small.jpg" />
      </div>
      <div class="slideshow-content">
        <img src="dead_like_me_small.jpg" />
      </div>
    </div>
  </div>
  <div id="slideshow-previous"></div>
  <div id="slideshow-next"></div>
</div>

As I mentioned earlier you can replace the img with any HTML content you want. That pretty much takes care of the html part.

CSS is up next, it is slightly more complicated than the html but nothing too crazy. The first piece to look at is the positioning and sizing of main slideshow area and scroller, which can have pretty much the same css. We do however add a border to our area to bring it out a little. The code below is fairly understandable, I make sure to set the position to relative so that I can easily position the next and previous buttons absolutely.

#slideshow-area, #slideshow-scroller {
  width: 500px;
  height: 500px;
  position: relative;
  overflow: hidden;
  margin: 0 auto;
}

#slideshow-area {
  border: 1px solid #000;
}
We are also going to set the height of the content holder to 500px, same as the area.


#slideshow-holder {
  height: 500px;
}
The next two items are the previous and next buttons. They take a little bit more work to make sure they are in the correct position. The buttons also have background images for pretty arrows (sorry IE6 users it may look bad since the arrows are png files). I also set the cursor to hand and pointer - for browser compatibility. And finally we also have classes to identify and float left each piece of content in the slideshow.


#slideshow-previous, #slideshow-next {
  width: 50px;
  height: 50px;
  position: absolute;
  background: transparent url("arrow_left.png") no-repeat 50% 50%;
  top: 225px;
  display: none;
  cursor: pointer;
  cursor: hand;
}

#slideshow-next {
  display: block;
  background: transparent url("arrow_right.png") no-repeat 50% 50%;
  top: 225px;
  right: 0;
}

.slideshow-content {
  float: left;
}

Well onto the real work, we now have to create the JavaScript to handle our functionality. jQuery makes this relatively simple though. First item is adding code to the document ready event.

var totalSlides = 0;
var currentSlide = 1;
var contentSlides = "";

$(document).ready(function(){
  $("#slideshow-previous").click(showPreviousSlide);
  $("#slideshow-next").click(showNextSlide);
 
  var totalWidth = 0;
  contentSlides = $(".slideshow-content");
  contentSlides.each(function(i){
    totalWidth += this.clientWidth;
    totalSlides++;
  });
  $("#slideshow-holder").width(totalWidth);
  $("#slideshow-scroller").attr({scrollLeft: 0});
  updateButtons();
});

The code starts out with a few variables that we will use. These hold the total number of slides, what slide we are currently on, and an array of content slides. Our document ready handler starts by adding click event handling to our previous and next buttons. We will define these functions shortly. Next, we figure out the total width of our content by using a simple selector on the slideshow-content class. We then run the results through jQuery’s each function adding the widths as we loop through the items and also counting number of slides.

Next we need to create the two functions showPreviousSlide and showNextSlide. These two functions do mainly three things: change current slide number, update the buttons, and scroll the content. These functions along with support functions are below.

function showPreviousSlide()
{
  currentSlide--;
  updateContentHolder();
  updateButtons();
}

function showNextSlide()
{
  currentSlide++;
  updateContentHolder();
  updateButtons();
}

function updateContentHolder()
{
  var scrollAmount = 0;
  contentSlides.each(function(i){
    if(currentSlide - 1 > i) {
      scrollAmount += this.clientWidth;
    }
  });
  $("#slideshow-scroller").animate({scrollLeft: scrollAmount}, 1000);
}

function updateButtons()
{
  if(currentSlide < totalSlides) {
    $("#slideshow-next").show();
  } else {
    $("#slideshow-next").hide();
  }
  if(currentSlide > 1) {
    $("#slideshow-previous").show();
  } else {
    $("#slideshow-previous").hide();
  }
}

Starting with the last function, updateButtons, it handles showing and hiding the the appropriate buttons. It looks at what the current slide is and compares it to how many we have or if it is greater than one – pretty easy stuff. The next function is where all the work is done for scrolling our area. We first figure out where we need to scroll to. This is done by adding the width’s of the previous slides together. Once the amount is calculated we just need to animate our scroller to the correct place using jQuery’s animate function. We pass the attribute to change and how long it should take to do it. With these functions called by our previous and next button clicks we have our slideshow.

That wraps up this tutorial. I hope that at least one person finds something they need from this guy. As always if anyone has any questions feel free to drop us a comment or send us a question through our contact form. Until next time, keep killing time on the Internet.

Image Editing: Saving, Cropping, and Resizing C# Tutorial

In C# it can be tiresome to do certain image editing functions using GDI+. This post has some fun editing methods which can come in handy at times. I have also included a nice little C# program to show all the functionality of the methods below.

Saving a Jpeg
The first thing to do here is set up the method signature with the input parameters. These are the save file path (string), the Image to save (System.Drawing.Bitmap), and a quality setting (long).

private void saveJpeg(string path, Bitamp img, long quality)

The next few things to do are setting up encoder information for saving the file. This includes setting an EncoderParameter for the quality of the Jpeg. The next thing is to get the codec information from your computer for jpegs. I do this by having a function to loop through the available ones on the computer and making sure jpeg is there. The line under that makes sure that the jpeg codec was found on the computer. If not it just returns out of the method.

The last thing to do is save the bitmap using the codec and the encoder infomation.

private void saveJpeg(string path, Bitmap img, long quality)
{
   // Encoder parameter for image quality
   EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, quality);

   // Jpeg image codec
   ImageCodecInfo jpegCodec = this.getEncoderInfo("image/jpeg");

   if(jpegCodec == null)
      return;

   EncoderParameters encoderParams = new EncoderParameters(1);
   encoderParams.Param[0] = qualityParam;

   img.Save(path, jpegCodec, encoderParams);
}

private ImageCodecInfo getEncoderInfo(string mimeType)
{
   // Get image codecs for all image formats
   ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

   // Find the correct image codec
   for (int i = 0; i < codecs.Length; i++)
      if (codecs[i].MimeType == mimeType)
         return codecs[i];
   return null;
}

Cropping
The method takes two objects – the image to crop (System.Drawing.Image) and the rectangle to crop out (System.Drawing.Rectangle). The next thing done is to create a Bitmap (System.Drawing.Bitmap) of the image. The only thing left is to crop the image. This is done by cloning the original image but only taking a rectangle of the original.

private static Image cropImage(Image img, Rectangle cropArea)
{
   Bitmap bmpImage = new Bitmap(img);
   Bitmap bmpCrop = bmpImage.Clone(cropArea,
   bmpImage.PixelFormat);
   return (Image)(bmpCrop);
}

Resizing
This next set of code is a slightly longer and more complex. The main reason this code is longer is because this resize function will keep the height and width proportional.

To start with we see that the input parameters are the image to resize (System.Drawing.Image) and the size (System.Drawing.Size). Also in this set of code are a few variables we use. The first two are the source height and width which is used later. And there are 3 other variables to calculate the proportion information.

private static Image resizeImage(Image imgToResize, Size size)
{
   int sourceWidth = imgToResize.Width;
   int sourceHeight = imgToResize.Height;

   float nPercent = 0;
   float nPercentW = 0;
   float nPercentH = 0;
}

The next step is to actually figure out what the size of the resized image should be. The first step is to calculate the percentages of the new size compared to the original. Next we need to decide which percentage is smaller because this is the percent of the original image we will use for both height and width. And now we calculate the number of height and width pixels for the destination image.

nPercentW = ((float)size.Width / (float)sourceWidth);
nPercentH = ((float)size.Height / (float)sourceHeight);

if (nPercentH < nPercentW)
   nPercent = nPercentH;
else
   nPercent = nPercentW;

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

The final thing to do is create the bitmap (System.Drawing.Bitmap) which we will draw the resized image on using a Graphics (System.Drawing.Graphics) object. I also set the interpolation mode, which is the algorithm used to resize the image. I prefer HighQualityBicubic, which from my testing seems to return the highest quality results. And just to clean up a little I dispose the Graphics object.

Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();

And this gives us the final code.

private static Image resizeImage(Image imgToResize, Size size)
{
   int sourceWidth = imgToResize.Width;
   int sourceHeight = imgToResize.Height;

   float nPercent = 0;
   float nPercentW = 0;
   float nPercentH = 0;

   nPercentW = ((float)size.Width / (float)sourceWidth);
   nPercentH = ((float)size.Height / (float)sourceHeight);

   if (nPercentH < nPercentW)
      nPercent = nPercentH;
   else
      nPercent = nPercentW;

   int destWidth = (int)(sourceWidth * nPercent);
   int destHeight = (int)(sourceHeight * nPercent);

   Bitmap b = new Bitmap(destWidth, destHeight);
   Graphics g = Graphics.FromImage((Image)b);
   g.InterpolationMode = InterpolationMode.HighQualityBicubic;

   g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
   g.Dispose();

   return (Image)b;
}

Happy nowruz

Nowruz marks the first day of spring and the beginning of the year in Iranian calendar. It is celebrated on the day of the astronomical vernal equinox, which usually occurs on March 21 or the previous/following day depending on where it is observed. As well as being a Zoroastrian holiday and having significance amongst the Zoroastrian ancestors of modern Iranians, the same time is celebrated in the Indian sub-continent as the new year. The moment the Sun crosses the celestial equator and equalizes night and day is calculated exactly every year and Iranian families gather together to observe the rituals.

Nowruz and the spring equinox

The first day on the Iranian calendar falls on the March equinox, the first day of spring. At the time of the equinox, the sun is observed to be directly over the equator, and the north and south poles of the Earth lie along the solar terminator; sunlight is evenly divided between the north and south hemispheres.

In ca. 11 century CE major reforms of Iranian calenders took place and whose principal purpose was to fix the beginning of the calendar year, i.e. Nowruz, at the vernal equinox. Accordingly, the definition of Nowruz given by the Iranian scientist Ṭūsī was the following: “the first day of the official new year [Nowruz] was always the day on which the sun entered Aries before noon”

How to re-create the Show desktop icon on the Quick Launch toolbar in Windows

Response to your questions

To re-create the Show desktop icon yourself, follow these steps:

  1. Click Start, click Run, type notepad in the Open box, and then click OK.
  2. Carefully copy and then paste the following text into the Notepad window:
    [Shell]
    Command=2
    IconFile=explorer.exe,3
    [Taskbar]
    Command=ToggleDesktop
  3. On the File menu, click Save As, and then save the file to your desktop as “Show desktop.scf”. The Show desktop icon is created on your desktop.
  4. Click and then drag the Show desktop icon to your Quick Launch toolbar.

Information for advanced users


The Quick Launch toolbar uses the files in the following folder:

%userprofile%\Application Data\Microsoft\Internet Explorer\Quick Launch 

More Infoemation …

How to use google Trends on nanotechnology

Response to your questions

Google Trends, graphs the number and source of searches on whatever term you wish. The results for nanotechnology:

Top ten countries
1. India
2. Iran
3. Singapore
4. Malaysia
5. South Korea
6. Thailand
7. United States
8. Australia
9. Canada
10. Taiwan

Top ten cities
1. Hyderabad, India
2. Chennai, India
3. New Delhi, India
4. Delhi, India
5. Mumbai, India
6. Tehran, Iran
7. Bangalore, India
8. Singapore, Singapore
9. Washington, DC, USA
10. Houston, TX, USA

Top ten languages
1. Korean
2. Thai
3. English
4. Chinese
5. Turkish
6. Italian
7. Dutch
8. Spanish
9. German
10. Portuguese

Google Rank Check How to See the Value Google Places on Your Page

Response to your questions

Do you want to do a Google rank check?

The page rank of Google is considered as an original algorithm.At the time finding your rank on the search results, Google takes over half a billion variables into consideration.There is no one even the individual that manages the code, who is aware about these variables.Therefore, you have to caution when someone claims to be an authority of Google Rank Check.Even then, we have some knowledge about the functioning of page rank.There are certain important pages, according to the Google which yields maximum page rank as compared to other pages.

Those pages which have high ranking generally comes at the top of the search engines, however you will notice that rank 5 pages at time ranks higher than rank 7 pages for a particular type of search.Even Google notices the links, appearing on the page, which acts as a vote for other web pages.So, if a highly ranked page links to your site, you get more “juice” out of it than when a friend with no page rank links to your site.If a website with .gov domain or .edu domain has a link to your website, it is assumed that your site is actually good because sites with above domains are non profit sites.By taking advertisements on the internet on college newspaper websites, you can get .edu links.But, any links from PR 2 or higher sites can help your page rank.

By posting comments with an honest page link is another of getting links.See to it that that the links are followed by the Google on the first page.There are some web owners who set up their websites so that you cannot avail any link from your post.This can be done by downloading free software from internet.

Some of the idea for increasing page rank contains:

Join forums and post a link back to your website in your signature.You will gain high amount of links once you are done with the post.

Then post your sites to various directories.Each directory which lists you will give you more of a chance of being listed higher in Google’s search results.

Your site should be added with an ezine.Not only will this allow you to keep up with the people who visit your site, but you can also post information about your ezine to ezine directories.

Articles should be posted on article sites.This will help you to grab the traffic.You can also get juice link from top PR sites.

Create a sitemap on your website.This lets Google know how to index your page.

Within your website, have a link to other pages.By placing link on the internal pages of your website, you can boost up your link page rank.

Continue building pages within your site.To increase the strength of your home page’s PR, link the created pages to your homepage.

The best way to get Google rank check is on your Firefox Browser get Google toolbar installed.Use the link http://www.google.com/tools/firefox/toolbar/FT3/intl/en/index.html to download that tool. Besides the above mentioned ways, you can also increase the ranking of your web page with Commission Ritual. Through Google rank check, you can know how your website is functioning in comparison with other similar websites.

How to get microsoft os version in c# and vb.net

Amator skill

I think it be a good idea to check the windows OS version .

//C#
{Console.WriteLine(Environment.OSVersion.Version.Major.ToString());}
'VB.NET
Console.WriteLine(Environment.OSVersion.Version.Major.ToString())

Microsoft os version table:

Release date Product name Current Version / Build Notes Last IE
November 1985 Windows 1.01 1.01 Unsupported
November 1987 Windows 2.03 2.03 Unsupported
May 1988 Windows 2.10 2.10 Unsupported
March 1989 Windows 2.11 2.11 Unsupported
May 1990 Windows 3.0 3.0 Unsupported
March 1992 Windows 3.1x 3.1 Unsupported 5
October 1992 Windows For Workgroups 3.1 3.1 Unsupported 5
July 1993 Windows NT 3.1 NT 3.1 Unsupported 5
December 1993 Windows For Workgroups 3.11 3.11 Unsupported 5
January 1994 Windows 3.2 (released in Simplified Chinese only) 3.2 Unsupported 5
September 1994 Windows NT 3.5 NT 3.5 Unsupported 5
May 1995 Windows NT 3.51 NT 3.51 Unsupported 5
August 1995 Windows 95 4.0.950 Unsupported 5.5
July 1996 Windows NT 4.0 NT 4.0.1381 Unsupported 6
June 1998 Windows 98 4.10.1998 Unsupported 6
May 1999 Windows 98 SE 4.10.2222 Unsupported 6
February 2000 Windows 2000 NT 5.0.2195 Extended Support until July 13, 2010[20] 6
September 2000 Windows Me 4.90.3000 Unsupported 6
October 2001 Windows XP NT 5.1.2600 Extended Support until July 13, 2010 for SP2 and April 8, 2014 for SP3. (RTM and SP1 unsupported). 8
March 2003 Windows XP 64-bit Edition (IA-64) NT 5.2.3790 Unsupported 6
April 2003 Windows Server 2003 NT 5.2.3790 Extended Support until July 13, 2010 for SP1, R2, SP2 (RTM unsupported). 8
April 2005 Windows XP Professional x64 Edition NT 5.2.3790 Current 8
July 2006 Windows Fundamentals for Legacy PCs NT 5.1.2600 Current 8
November 2006 (volume licensing)
January 2007 (retail)
Windows Vista NT 6.0.6002 Extended Support until April 10, 2012
Version changed to NT 6.0.6001 with SP1 (February 4, 2008) and to NT 6.0.6002 with SP2 (April 28, 2009).
8
July 2007 Windows Home Server NT 5.2.4500 Extended Support until August 01, 2013 8
February 2008 Windows Server 2008 NT 6.0.6002 Extended Support until July 9, 2013
Version changed to NT 6.0.6002 with SP2 (April 28, 2009).
8
October 2009 [21] Windows 7 and Windows Server 2008 R2 NT 6.1.7600 Current 8
2012 Windows 8 Unknown Upcoming Unknown

Some Notes On Invoking

One nice thing about C# is that you can be holding a string in your hand, and get your fingers on the method or property that is actually represented by that string – using Reflection and Invoke. This is not unique to C# by any means, and in fact in a number of other languages it is a lot easier to do (such as PHP), but it is there and you can use it. But one thing to remember is that Invoke is a costly operation – you don’t want to be doing it when you don’t have to be.

Recently, I wrote a piece of code that had access to some method attributes, and needed to find the correct method to call on an object based on those attributes. Essentially, I wanted to be able to add and remove “abilities” (other methods) to the object without needing to modify the code that is calling these methods. And in my initial iteration of the code, I ended up calling Invoke a lot. And it was slow. So I took a look at the code, and came up with a way around this problem, but while still using reflection.

Here is a very simplistic representation of the type of action I was performing:

using System;
using System.Reflection;

namespace SillyReflection
{
  class Program
  {
    static void Main(string[] args)
    {
      MyTestObject obj = new MyTestObject();

      MethodInfo mi = typeof(MyTestObject).GetMethod("Increment");

      for(int i=0; i<5000000; i++)
        mi.Invoke(obj, null);
    }
  }

  public class MyTestObject
  {
    private int _counter = 0;

    public void Increment()
    {
      _counter++;
    }
  }
}

This code is slow, taking just under 17 seconds to complete on my computer – compared to 0.1 seconds to complete if the Increment method was called directly. Granted, the above code is kind of silly (to put it lightly) – but there are situations where its equivalent can arise in a much more complicated manner.

Now, it is true that in my situation there is probably a way to get by without ever using Invoke at all – but the particular paradigm I was using lent itself to some nice clean looking code. So I wanted to preserve that if possible. And one of the solutions I came up with was not to Invoke the method I actually wanted to call, but to instead Invoke a thunk. Essentially, a method that returns a delegate representing the actual method that I wanted to call. And once I had that delegate in my hands, I would store it, and anytime I needed to hit against that method again I would use the delegate instead of Invoking against the object. This meant that I only needed to do an Invoke call once per method, instead of once per call.

Here is what the above code looks like when modified to work in this fashion:

using System;
using System.Reflection;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      MyTestObject obj = new MyTestObject();
     
      MethodInfo mi = typeof(MyTestObject).GetMethod("GetIncDelegate");

      NoArgDelegate del = (NoArgDelegate)mi.Invoke(obj, null);
      for (int i = 0; i < 5000000; i++)
        del();
    }
  }

  public delegate void NoArgDelegate();

  public class MyTestObject
  {
    private int _counter = 0;

    public void Increment()
    {
      _counter++;
    }

    public NoArgDelegate GetIncDelegate()
    {
      return new NoArgDelegate(Increment);
    }
  }
}

In this case, performance is almost equivalent to calling the method directly – 110 milliseconds vs. 100 milliseconds (and a difference of 10 milliseconds here is essentially meaningless). This is because we are only doing 1 Invoke call instead of 5 million, and calling a delegate is just ever so slightly more expensive then a regular method (or so I have read).

Here is all the code together complete with timing stuff – you should be able to copy this into Visual Studio and play around for yourself:

using System;
using System.Reflection;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      long ticks = Environment.TickCount;
      MyTestObject obj = new MyTestObject();
      for (int i = 0; i < 5000000; i++)
        obj.Increment();
      Console.WriteLine(Environment.TickCount - ticks);

      ticks = Environment.TickCount;
      obj = new MyTestObject();
      MethodInfo mi = typeof(MyTestObject).GetMethod("Increment");
      for (int i = 0; i < 5000000; i++)
        mi.Invoke(obj, null);
      Console.WriteLine(Environment.TickCount - ticks);

      ticks = Environment.TickCount;
      obj = new MyTestObject();
      mi = typeof(MyTestObject).GetMethod("GetIncDelegate");
      NoArgDelegate del = (NoArgDelegate)mi.Invoke(obj, null);
      for (int i = 0; i < 5000000; i++)
        del();
      Console.WriteLine(Environment.TickCount - ticks);

      Console.Read();
    }
  }

  public delegate void NoArgDelegate();

  public class MyTestObject
  {
    private int _counter = 0;

    public void Increment()
    {
      _counter++;
    }

    public NoArgDelegate GetIncDelegate()
    {
      return new NoArgDelegate(Increment);
    }
  }
}

And so there you go – don’t go crazy using Invoke. Which is not to say avoid it altogether – besides the fact that in some situations you are required to use it, it (and other Reflection stuff) enable us to write some pretty cool code. Just remember that there are performance costs here, and balance that against what you are trying to do.

What are the country codes EAN – UPC JAN ?

GS1 Prefixes do not provide identification of country of origin for a given product.

They simply provide number capacity to different countries for assignment from that location to companies who apply. Those companies in turn may manufacture products anywhere in the world.

ASSIGNED GS1 PREFIXES
000 – 019 GS1 US
020 – 029 Restricted distribution (MO defined)
030 – 039 GS1 US
040 – 049 Restricted distribution (MO defined)
050 – 059 Coupons
060 – 139 GS1 US
200 – 299 Restricted distribution (MO defined)
300 – 379 GS1 France
380 GS1 Bulgaria
383 GS1 Slovenija
385 GS1 Croatia
387 GS1 BIH (Bosnia-Herzegovina)
389 GS1 Montenegro
400 – 440 GS1 Germany
450 – 459 & 490 – 499 GS1 Japan
460 – 469 GS1 Russia
470 GS1 Kyrgyzstan
471 GS1 Taiwan
474 GS1 Estonia
475 GS1 Latvia
476 GS1 Azerbaijan
477 GS1 Lithuania
478 GS1 Uzbekistan
479 GS1 Sri Lanka
480 GS1 Philippines
481 GS1 Belarus
482 GS1 Ukraine
484 GS1 Moldova
485 GS1 Armenia
486 GS1 Georgia
487 GS1 Kazakstan
488 GS1 Tajikistan
489 GS1 Hong Kong
500 – 509 GS1 UK
520 GS1 Global Office
528 GS1 Lebanon
529 GS1 Cyprus
530 GS1 Albania
531 GS1 MAC (FYR Macedonia)
535 GS1 Malta
539 GS1 Ireland
540 – 549 GS1 Belgium & Luxembourg
560 GS1 Portugal
569 GS1 Iceland
570 – 579 GS1 Denmark
590 GS1 Poland
594 GS1 Romania
599 GS1 Hungary
600 – 601 GS1 South Africa
603 GS1 Ghana
608 GS1 Bahrain
609 GS1 Mauritius
611 GS1 Morocco
613 GS1 Algeria
615 GS1 Nigeria
616 GS1 Kenya
618 GS1 Ivory Coast
619 GS1 Tunisia
621 GS1 Syria
622 GS1 Egypt
624 GS1 Libya
625 GS1 Jordan
626 GS1 Iran
627 GS1 Kuwait
628 GS1 Saudi Arabia
629 GS1 Emirates
640 – 649 GS1 Finland
690 – 695 GS1 China
700 – 709 GS1 Norway
729 GS1 Israel
730 – 739 GS1 Sweden
740 GS1 Guatemala
741 GS1 El Salvador
742 GS1 Honduras
743 GS1 Nicaragua
744 GS1 Costa Rica
745 GS1 Panama
746 GS1 Republica Dominicana
750 GS1 Mexico
754 – 755 GS1 Canada
759 GS1 Venezuela
760 – 769 GS1 Schweiz, Suisse, Svizzera
770 GS1 Colombia
773 GS1 Uruguay
775 GS1 Peru
777 GS1 Bolivia
779 GS1 Argentina
780 GS1 Chile
784 GS1 Paraguay
786 GS1 Ecuador
789 – 790 GS1 Brasil  
800 – 839 GS1 Italy  
840 – 849 GS1 Spain  
850 GS1 Cuba
858 GS1 Slovakia
859 GS1 Czech
860  GS1 Serbia
865 GS1 Mongolia
867 GS1 North Korea
868 – 869 GS1 Turkey
870 – 879 GS1 Netherlands
880 GS1 South Korea
884 GS1 Cambodia
885 GS1 Thailand
888 GS1 Singapore
890 GS1 India
893 GS1 Vietnam
896 GS1 Pakistan
899 GS1 Indonesia
900 – 919 GS1 Austria
930 – 939 GS1 Australia
940 – 949 GS1 New Zealand
950 GS1 Global Office
955 GS1 Malaysia
958 GS1 Macau
977 Serial publications (ISSN)
978 – 979 Bookland (ISBN)
980 Refund receipts
981 – 982 Common Currency Coupons
990 – 999 Coupons
Note: Prefixes not assigned yet are reserved for future use.

Information and structure barcode UPC *Universal Product Code*

The UPC encodes 12 decimal digits as SLLLLLLMRRRRRRE, where S (start) and E (end) are the bit pattern 101, M (middle) is the bit pattern 01010 (called guard bars), and each L (left) and R (right) are digits, each one represented by a seven-bit code. This is a total of 95 bits. The bit pattern for each numeral is designed to be as little like the others as possible, and to have no more than four consecutive 1s or 0s in order. Both are for reliability in scanning.

Since S, M, and E all include two bars, and each of the 12 digits of the UPC-A barcode consists of two bars and two spaces, all UPC-A barcodes consist of exactly (3 × 2) + (12 × 2) = 30 bars.

The UPC has only numerals, with no letters or other characters. The first digit L is the prefix. The last digit R is an error correcting check digit, allowing some errors in scanning or manual entry to be detected. UPC data structures are a component of GTINs (Global Trade Item Numbers). All of these data structures follow the global GS1 standards.

The bar-and-space patterns for each digit 0–9 are as follows:

Digit L Pattern R Pattern
0 0001101 1110010
1 0011001 1100110
2 0010011 1101100
3 0111101 1000010
4 0100011 1011100
5 0110001 1001110
6 0101111 1010000
7 0111011 1000100
8 0110111 1001000
9 0001011 1110100

A binary 1 is always indicated by a black bar while a 0 is indicated by a white space. Numbers on the right side of the middle guard bars are optically the inverse of the numbers to the left. In other words, while a number on the left side of the UPC will be made up of black bars and white spaces, the same number on the right side would be indicated by the inverse (what was black on the left is now white and what was white is now black).

In the illustraction above, the “4” digit (shown in detail), is 1011100 (bar x 1, space x 1, bar x 3, space x 2). If the “4” digit were on the left hand side it would be 0100011 (space x 1, bar x 1, space x 3, bar x 2). This inversion enables the barcode to be scanned from left-to-right or right-to-left. Since the same number is represented differently based on where it lies in the code the scanning software knows if it read the code the correct way or upside down.

Continue reading Information and structure barcode UPC *Universal Product Code*