jTag : A jQuery plugin to tag pictures & more !
Howdy,
A little while ago I published an article on how to create a facebook like tagging system.
Even thought It worked fine it was a bit messy and kinda hard to impletement.
I then started to work on a jQuery plugin that make that feature a lot easier to integrate on your solutions.
What does it look like ?
Click on the picture to start tagging

I made more demos to explain all the options of the script.
Where do I get it ?
You can get the source code on github or git clone git://github.com/djpate/jTag.git
Does it work on all browsers ?
This plugin was tested on FF 3.5+, IE7+ & chrome 8+
I dont really know about the rest but let me know in your comments !
What are the requirements ?
Obviously since this is a jQuery plugin you need jQuery ( tested on 1.4 +)
For the resize, drag & autocomplete features you need jQuery ui (tested on 1.8.7)
Everything is included in the source code.
How do I install it ?
First make sure you have jQuery if not add this to your head section
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></script>
Then install jQuery ui
If you dont need anything else from jQuery ui you can create a stripped down version on there site(select only resize,drag & autocomplete).
add this to your head section
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js'></script> <link media="screen" rel="stylesheet" href="css/jquery-ui.custom.css" type="text/css" />
then install the minified version of my script, add this to your head section
<script type='text/javascript' src='js/jquery.tag.min.js'></script> <link media="screen" rel="stylesheet" href="css/jquery.tag.css" type="text/css" />
How do I use it ?
Right now you can only use it on one image at a time !
Basicly you use it like that
<img src="someimg" id="myimg" />
<script>
$("#myimg").tag();
</script>
This will start the plugin with all the default options.
Options & callbacks
| name | default value | possible values | more info |
|---|---|---|---|
| minWidth | 100 | an integer in px | The tag area minimum width |
| maxWidth | null | an integer in px | The tag area maximum width |
| minHeight | 100 | an integer in px | The tag area minimum height |
| maxHeight | null | an integer in px | The tag area maximum height |
| defaultWidth | 100 | an integer in px | The tag area default width |
| defaultHeight | 100 | an integer in px | The tag area default height |
| canTag | true | true|false | If the user can tag this picture (sometimes you are only showing tags) |
| canDelete | true | true|false | If the user can delete tags on this picture |
| draggable | true | true|false | If the user can drag the tag window |
| resizable | true | true|false | If the user can resize the tag window |
| clickToTag | true | true|false | If the user can click the picture to tag it |
| autoShowDrag | false | true|false | If the tag window should be launch at initialization |
| showTag | hover | hover|always | When tags should be viewed |
| showLabels | true | true|false | Show labels of tags underneath the image |
| autoComplete | null | anything that jQuery ui accept ( for example [ 'chris','john' ] ) | Autocomplete values |
| defaultTags | null | [{'id':1,'label':'Uncle jack','width':150,'height':190,'top':50,'left':160}] | Check out demo 5 for more info |
| save | null | a callback function ( for example function(width,height,top_pos,left,label,the_tag){} ) | This will help you for ajax call when your tags are stored on the db (check out demo 6) |
| remove | null | a callback function ( for example function(id){alert(‘id’)} ) | This will help you for ajax call when your tags are stored on the db (check out demo 6) |
Now if you want to apply an option just use
<img src="someimg" id="myimg" />
<script>
$("#myimg").tag({optionName: value});
</script>
Additional methods
| Method name | info |
|---|---|
| hideDrag() | Hide the tag window if visible |
| showDrag() | show the tag window if not yet active |
| enableClickToTag() | enable the click to tag feature |
| disableClickToTag() | disable the click to tag feature |
| addTag(width,height,top_pos,left,label,id) | Manually add a tag, id is optional |
| setId(id) | should be called in your save callback on the tag object and “id” should be the id the created tag in your db |
I you like it leave a comment
Have fun !

i can’t syn with live() jquery function ???, please help
hello all, i m hving problem with addtag , i need to save tag for picture, picture tag is saved ok, values are taken ok based on id of pic, but addtag not working for me to make tag, i see when i put alert and alert comes, i may wait for site to be loaded fully and then press ok of alert , it then show some tags, i m not known with jquery development therefore having issue, but i know that there is some little bug only. please help me
I want to have a move tag function, and I’ve try but I cannot achive
nice post!
i cant share this link : https://djpate.com/2011/01/14/jtag-a-jquery-plugin-to-tag-pictures-more
am i doing it wrong ?
hello i`m trying to make the full tag clickable how do i do please tell me
Hi, Christophe!
Really a very useful plugin.
Once I’ve needed a click feature for the tags in one of my projects, I implemented that and also fixed the feature of not displaying the delete button when canDelete equals to false.
I can send the code to you if you want. Just let me know how
Thanks and regards,
Daniel Campos.
danielalvarengacampos(at)gmail.com
Hello Daniel,
if you fixed a bug you can submit it via github by making a pull request on the repository.
Cheers.
Hello Christophe, great plugin!.
How can I add an image to the autocomplete list?
I want to show the list in this format: image – text
Thank you.
Dear,
I am trying to add a remove anchor beside the labels under the image.
I reached to edit in the jquery.tag javascript source file like this:
if (options.showLabels) {
$(“” + label + “remove“).insertBefore($(“.jTagLabels div:last”));
}
i only add this part:
remove
but this code is not running because of $(this).parent().parent().getId() is undefined.
when i replace it by a specific id from my db , it works and removes the label.
so i need to know what is the right script to get the id and assign it to the function options.remove()
please reply asap.
thanks,
ASA
it’s awesome n i like it 2….n thanks sir….
Hi , First Thanks for your effort
i write a ajax function that get All Tags from Db and
put him in a var tags with the formates (e.g. [{ 'id': 1, 'label': 'aaaa', 'width': 100, 'height': 100, 'top': 0, 'left': 3 }])
and in .tag ()
i put
defaultTags : tags ;
but no thing is happened i tried alot but with no new
here’s my code::
$(“#img1″).tag(
{
defaultTags: tags,
save: function (width, height, top_pos, left, label, the_tag) {
saveInDb(width, height, top_pos, left, label);
alert(‘I can save this tag (‘ + width + ‘,’ + height + ‘,’ + top_pos + ‘,’ + left + ‘,’ + label + ‘,’ + the_tag + ‘)’);
the_tag.setId(‘someIdFromMyDb’);
},
remove: function (id) {
alert(‘Here I can do some ajax to delete tag #’ + id + ‘ in my db’);
}
});
function getTags() {
$.ajax({
type: “POST”,
url: “Default.aspx/GetTags”,
data: ”,
contentType: “application/json; charset=utf-8″,
dataType: “json”,
success: function (result) {
processData: false,
// alert(result.d);
tags = result.d;
return result.d;
}
});
Note:
i tested function getTags() and saveInDb()
Hello,
I created a new tutorial in the repo to help you to get it to work in the db.
I got the same as you did for the defaultTags values so I’m checking it out but you can use the method I’ve used in the new tutorial as a workaround.
Check it out and let me know if that helps you !
hello,
thanks for your news tutorial it helps me , and i use addTag() fn to do my task ,…..
But i have an urgent problem,
that in demo 2 u disable and enable tagging to image, i want also to enable image eventClick to get the next image to preview .
thus i want to be able to click image first , at the same time tag the image if user click tag this image …..
thanks in advance , ASA
hi
nice work. Demo 7 shows a 404
i love
Not sure why, but the example on this page (Simpsons) doesn’t work for me properly in FF5. Tags are always top left. Other examples on your demos page seem fine…
Awsome! Works like a charm!
Great job
Hello Sir,
I am trying to make a unique save callback function for each image (multiple images), the problem I noticed is that only one Save function can be implemented per image, even though different tags can be specified.
Apparently the last save callback function specified will be saved for all, although this makes it difficult to save the tags to a reference of my image on the backend, so it can be redisplayed properly.
Can you advise how the code could be modified to allow for unique callback save functions per image?
Could you give some example code ?
Hi There!
I”m trying to have the “clickToTag” enabled after clicking the enable button, instead of having the “enable” button show the drag (showDrag()), any suggestions? here is my code:
$(“#img1″).tag({
clickToTag: false
});
$(“#enable”).click(function(){
$(“#img1″).enableClickToTag();
});
in autoComplete i need the image also but this is not working at all
my code is like :
———————
$img = “”;
autoComplete:[
],
the problem is : it is showing all these things
like :
mihir
——————-
actually in I saw source code in in decode form like << and >
———–
please tell me the solution
I would be happy to help you but I didn’t understand a word you said
If i have a picture (1000x1000px) inside a div(100x100px – with overflow: auto) and i’m at the bottom of the div, clicking on the image will place the tag to the top.
Any tips for this little bug?
Thanks,
Alex.
Do you have a link I can look at ?
http://62.231.98.190/tag/demo/1.html scroll at the bottom and click to add tag. tag is added at the top
Umm, I’ll try to check it out but basicly the issue is that I use offsetLeft et offsetTop to position the tag window but since it’s relative to it’s parent and that the parent is smaller than the image itself… I’ll check it out.
If you want to debug yourself you can check out https://github.com/djpate/jTag/blob/master/source/jquery.tag.js#L202
Very nice.I like the lil zoom effect while moving the tag. To bad it is not sizeable.
It should be… What browser are you using?
Hey,
Nice plugin. I have one simple question: is there any way to move the buttons above the selected area, without modifying the core?
Thanks,
Alex.
Not at this time.
Any suggestions on how to make this work with more than 1 image at a time? I guess that means only 1 image per page? I’d like to have it work with multiple images on a page.
Thanks!
I rewrote the plugin this morning…
It’s on github but It may be a bit buggy since I did not have a chance to do some extensive testing…
Thanks for the script man! I’ll be like you someday when I become a pro programmer! : )
Thanks for the script.
Actually yes, jQuery made a bad decision when the release 1.6 because they removed the attr() function. If I decided to change the script to work with the new prop() function It would mess up everyone with 1.5 and below.
The solution is to take the 1.6.1 version because they decided to restore the attr() function
http://blog.jquery.com/2011/05/10/jquery-1-6-1-rc-1-released/
Cheers
Thanks for the great script. I had a little headache installing it because it doesn’t seem to work properly with the newest version of jQuery (1.6) that I was using. It was causing the image inside the selection window to freeze.
It worked great once I downgraded to 1.4.4 like you use in the demos.
Any idea why this issue exists? (Same results in FF4 and IE8)
Thanks again for the great tool!
tnx it will help my site
Congratulations! Beautiful Script…
This also works in OPERA 11.. I’m browsing through it..
Kind Regards!!
Very nice, I’d like to see one more feature implemented though. I noticed that in the save/delete callbacks, there is no reference to the actual image that is being tagged. Can you adjust the callback params to include at least the image src attribute so I can actually match a tag with an image server side?
Thanks,
Mike.
Did you check out the setId feature or do you really need the src tag ?
Nice plugin dude……
Great tutorial, just what I was looking for. I have tried to change it so that a copy of the same image is tagged each time for a car auction site.
The person listing the vehicle is allowed to tag the picture and remove the tags, but other users can only view the tags, but I cannot get the page to display.
Can I send you the page so you can take a look for me?
Thanks
sure
How can i set a default name to a tag. Eg, a user who is login, can only tag his picture. So he can only tag once and it will automatically write his name. He can’t write himself.
You cannot do that with the script as it is right now.
Basicly you’ll have to remove the input, then add an option so you can set the default value and change the script accordingly. shouldn’t take too long.
nice, great work. it would be better if you could demonstrate it working just like facebook tagging, with list of names on the bottom, when hover it, it’ll show the box tag on the picture
Thanks I’m working on it
Oops .. sorry … I just tested the demo it works.
I was testing on post page it self.
great thanks … it is awesome
it is not working in my firefox 3.6.13
Are you testing from my demos?
Great! Have been trying to find such a plugin since a long time now..:P