Jump to content
UBot Underground

Apply Alt Tags To Images Any Scripts Out There


Recommended Posts

Hi

Is there any scripts that can apply alt tags to images.

I have some code that downloads an image from a url and names it with a given name, I now need to write the Name also to the Alt Tag of the image.

 

Is this possible anyone have any thoughts on how to do it.

 

Many thanks

Andrew

Link to post
Share on other sites

Hey,

 

You would need to use $scrape attribute and instead of src use alt

navigate("http://ubotdocta.com/ubot-stealth-boot-camp/advanced-training/2016/12/10/ubot-boot-camp-advanced-the-define-command-making-custom-commands-and-functions/","Wait")
wait for element(<id="site-info">,20,"Appear")
set(#alt,$scrape attribute(<title="define command">,"alt"),"Global")
alert(#alt)
set(#A,"filename-{#alt}.png","Global")

Regards,
Nick

  • Like 1
Link to post
Share on other sites

Hi Nick,

 

So my current code is below, I presume I could just add a command into the download file section that also adds the alt tag from row,0

or would I still need to set the command Alt ?

 

many thanks Andrew

 

clear table(&images)
create table from file("C:\\Users\\Andrew\\Desktop\\silverim.csv",&images)
set(#row,0,"Global")
create folder($special folder("Desktop"),"Silverstone Images")
set(#path,"{$special folder("Desktop")}/Silverstone Images/","Global")
loop($table total rows(&images)) {
    download file($table cell(&images,#row,1),"{#path}{$table cell(&images,#row,0)}.jpg")
    increment(#row)
}

Link to post
Share on other sites

FIO my sliverim.csv folder that I pull into the table has

new name and url in it

 

so I grab the image from the url and apply the name, so just need to apply the same name to the alt tag.

 

I don't want to scrape the current alt tag, just write to it as I am when downloading and naming the image.

 

hope that makes sense.

Link to post
Share on other sites

If you mean the metadata you can use this: http://wiki.ubotstudio.com/wiki/Edit_jpeg_metadata

 

I think that the image commands don't work in compiled though, in that case you can call Image Magick directly via command line arguments: https://imagemagick.org/script/command-line-processing.php

  • Like 1
Link to post
Share on other sites

No, not really, I am more confused now.

 

You want to name the image file

 

url-new_name.jpg

 

or change the metadata?

 

The file name you can concatenate however you wish.

Show an example of what your csv file row is

and show an example of the output you would like.

 

csv row

 

http://ubotdocta.com,keyword(alt- tag)


renamed file
ubotdocta.com-keyword.jpg

 

While downloading the file you can name it whatever you wish instead of making another loop. Unless it is a ton of images. Then you will run out of memory.

 

Regards,
Nick

Link to post
Share on other sites

No its the meta data I want to amend also.

 

File name is all sorted and working fine, its apply the same file name from my csv as I am to the downloaded image also to the metadata.

 

sorry for any confusion.

Link to post
Share on other sites
HelloInsomnia ,

you are correct its the metadata I am now trying to apply, the file download and re-name to what I specify is working great, I just wanted to if possible add another feature which was to put the title "which is what I am naming the downloaded image" into the metadata.

Link to post
Share on other sites

Nick,

 

There are thousands of images pulled at any one time.

FIO they are all named 0.jpg or 1.jpg so they need to be pulled and named Lot_x"title".jpg and cycle through them all, that is working fine with the above, I just wanted to then quickly if possible at the same time write to the metadata the same naming I am doing to the image.

 

Hope that is more clear.

many thanks

Andrew

Link to post
Share on other sites

Yes the path of where the image will be, as I will be downloading them one by one,

so the path is set by the table in the code also the name is being set as its the same name as what I am naming the image.

 

Hope that follows :

 

Currently the code takes the url in coll 1 / downloads it to folder "Silverstone Images" on the desktop and gives it the name specified in coll 0

I need to work out the required code to tell it that "this images just downloaded from the specifications given is located here. and apply the same name from the table to the meta data comment.

 

I am going through the table one image at a time and downloading and naming, maybe its not possible to add the meta data as it downloads each image, maybe I have to download them all then create a new table with the image location and name and cycle through them adding the meta comment.

That maybe a simpler way to do it, as I know what they will be called and where they will be, so maybe I just create another csv with that data and pull that into a new table after it has finshed downloading them all and then get it to apply the meta comment.

 

 

 

clear table(&images)
create table from file("C:\\Users\\Andrew\\Desktop\\silverim.csv",&images)
set(#row,0,"Global")
create folder($special folder("Desktop"),"Silverstone Images")
set(#path,"{$special folder("Desktop")}/Silverstone Images/","Global")
loop($table total rows(&images)) {
    download file($table cell(&images,#row,1),"{#path}{$table cell(&images,#row,0)}.jpg")
    increment(#row)
}

Link to post
Share on other sites

So it is naming and downloading them correctly right?

You just now want to apply metadata to the image?

 

If that's the case I took a quick peek and it looks like maybe this tool will do the job: https://www.sno.phy.queensu.ca/~phil/exiftool/

 

It has command line options so you can call it using the shell command. if you look at the examples for the first one here: https://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#WRITING-EXAMPLES

 

You could  do something like this:

clear table(&images)
create table from file("C:\\Users\\Andrew\\Desktop\\silverim.csv",&images)
set(#row,0,"Global")
create folder($special folder("Desktop"),"Silverstone Images")
set(#path,"{$special folder("Desktop")}/Silverstone Images/","Global")
loop($table total rows(&images)) {
    set(#saveImagePath,"{#path}{$table cell(&images,#row,0)}.jpg","Global")
    download file($table cell(&images,#row,1),#saveImagePath)
    shell("exiftool -Comment=\'This is a new comment\' {#saveImagePath}")
    increment(#row)
}
Link to post
Share on other sites

Many thanks

 

Naming and downloading is correct yes "that side is working perfect"

 

I have looked at that tool about 3 years ago, thank you for reminding me of it.

I can get it to do everything but it is just clearing all existing the metadata and not writing anything to it.

hmhmhmhm

 

path seems correct as it is now finding and wiping the data but won't write the comment will look into the tool again and see if I can figure out why its not now writing the updated info.

Link to post
Share on other sites
  • 1 month later...

Ok so I have finally got my head around the exif tool and the commands that I use to do what I need are below and do exactly what I am after on a folder of files, ie will be the download images from the above bot.

 

What would the command be to enable ubot to action the commands below from within UBot so I don't have to apply them outside Ubot.

 

So not to confuse, the current Ubot, just downloads and names the files based on a csv, I want to after it has finished downloading all the images at that stage run these commends

 

Many thanks Andrew:

 

perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$ //;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage
perl c:\windows\exiftool.pl -artist="Silverstone Auctions" -copyright="2019 Silverstone Auctions" C:\Users\Andrew\Desktop\testimage
perl c:\windows\exiftool.pl -subject="Silverstone Auctions AUTOSPORT INTERNATIONAL SHOW SALE 12th January 2019" C:\Users\Andrew\Desktop\testimage
perl c:\windows\exiftool.pl -creator="Silverstone Auctions" C:\Users\Andrew\Desktop\testimage
perl c:\windows\exiftool.pl -P -r "-description<${filename;s/\.[^\.]+$ //;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage
perl c:\windows\exiftool.pl -P -r "-IFD0:XPSubject<${filename;s/\.[^\.]+$ //;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage
perl c:\windows\exiftool.pl -P -r "-IFD0:XPComment<${filename;s/\.[^\.]+$ //;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

 

Edited by a-harvey
Link to post
Share on other sites
  • 1 month later...

Thanks Nick, I will look at this also, yes I am subscribed.

I might be able to use that function, to grab the metadata after written and use that as a way to populate a instagram upload "ie the title etc"

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...