View Full Version : Get an image from URL and rename
danielito10
May 6th, 2013, 09:25 PM
Hello,
I have a large list in excel with 2 columns, column A is a number, ie: 999999. Column B is an URL of an image, ie: http://www.xyz.com/images/123456.jpg.
I need to download the image to my server by ssh and immediately modify it to the number as in column A so the filename that will be stored in my server will be 999999.jpg instead 123456.jpg. Is that possible?
If not, how can I just download multiples images running one command and not copying the URL one by one. ie:
http://www.xyz.com/images/123457.jpg
http://www.xyz.com/images/123458.jpg
http://www.xyz.com/images/123459.jpg
http://www.xyz.com/images/123450.jpg
Thank you!!
Dan.
ofnuts
May 6th, 2013, 09:47 PM
To download a list of URLs, see "wget -i" or loop over the list and use curl).
danielito10
May 6th, 2013, 10:10 PM
Thank you for the quick reply.
Sorry I'm new in ssh commands. Can you please tell me an example how to copy the list I have in excel? It should be:
wget -i http://www.xyz.com/images/123457.jpg http://www.xyz.com/images/123458.jpg , etc?
Where should I copy the complete list of URL I have?
Thanks again!!
schragge
May 6th, 2013, 10:50 PM
You should pass wget -i (http://www.gnu.org/software/wget/manual/html_node/Logging-and-Input-File-Options.html) a text file containing URLs. Excel and LibreOffice Calc allow exporting data in CSV (http://en.wikipedia.org/wiki/Comma-separated_values)-format. Do it, then extract URLs and numbers from CSV with shell's read, cut, sed, awk, perl, or some specialized tools like csvtool (http://manpages.ubuntu.com/manpages/raring/en/man1/csvtool.1.html), xml2 (http://manpages.ubuntu.com/manpages/raring/en/man1/xml2.1.html), ffe (http://manpages.ubuntu.com/manpages/raring/en/man1/ffe.1.html). Alternatively to CSV, you may use TSV (http://en.wikipedia.org/wiki/Tab-separated_values) if Excel supports it.
Vaphell
May 7th, 2013, 03:08 AM
export your file to CSV format (comma-separated values) and open it in some text editor (eg gedit). You should get something like this:
111,"http://www.xyz.com/images/123457.jpg"
222,"http://www.xyz.com/images/123458.jpg"
333,"http://www.xyz.com/images/123459.jpg"
this short code should do the trick
while IFS=, read -r n url; do url=${url//\"/}; wget $url -O $n.jpg; done < urls.csv
this tells bash to read the file urls.csv line by line, use comma to cut it to fields named n and url and use them to construct wget command (wget url -O output_file)
Valpskott
May 7th, 2013, 10:19 AM
Here's an quick and dirty solution. Mark and copy all the numbers from the first row, and paste it into a file that is "list1.txt" in your ssh session ("nano list1.txt" then press "ctrl + shift + v" to paste, and then "ctrl + o" to save).
Then copy the urls and paste it into a file that is "list2.txt"
Then paste this command into your ssh session. "nano download.sh && chmod +x download.sh" (without the quotes)
While in nano, paste these lines of code.
#!/bin/bash
line="1"
if [ ! -e pics ]; then
mkdir pics
fi
while read number
do
url=$(awk "NR==$line" list2.txt)
file=$(echo $url | sed -e 's/.*\///g')
wget $url &>/dev/null
mv $file pics/$number.jpg
line=$(($line + 1))
done < "list1.txt"
Save the file with "ctrl + o" (o as in Oscar)
then just type ./download.sh
Voila! All the pictures should now be in a new diretory called "pics" with the names from list1 :)
Vaphell
May 7th, 2013, 11:19 AM
why bother? CSV is supported by any spreadsheet on earth, there is no risk of data misalignment (user can easily make error while copypasting) and a oneliner is way simpler than a dozen lines in a script.
danielito10
May 12th, 2013, 08:14 PM
Thank you very much to all of you!
rickyhu
March 19th, 2014, 04:29 AM
Hello,
I have a large list in excel with 2 columns, column A is a number, ie: 999999. Column B is an URL of an image, ie: http://www.xyz.com/images/123456.jpg.
I need to download the image from URL (http://www.rasteredge.com/how-to/vb-net-imaging/download-from-url/) to my server by ssh and immediately modify it to the number as in column A so the filename that will be stored in my server will be 999999.jpg instead 123456.jpg. Is that possible?
If not, how can I just download multiples images (http://www.rasteredge.com/how-to/vb-net-imaging/) running one command and not copying the URL one by one. ie:
http://www.xyz.com/images/123457.jpg
http://www.xyz.com/images/123458.jpg
http://www.xyz.com/images/123459.jpg
http://www.xyz.com/images/123450.jpg
Thank you!!
Dan.
First thank you for posting this question but could you please mark the solution instead of just saying thank you. ;)By the way, my issue is how to rename the image based on Column values. I know how to load image from url and export it into Excel, right now. So your sharing will be a great help for me. Thanks in advance.:P
Vaphell
March 19th, 2014, 10:18 AM
better start new thread instead of hijacking this one, even if the problem is very similar.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.