-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownloadImages.ps1
143 lines (92 loc) · 3.75 KB
/
DownloadImages.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
$path = (Get-Item -Path ".\" -Verbose).FullName
$downloadFolder = $MyInvocation.Path+"Library_Images"
# Figure out if the folder we will use to store the downloaded images already exists
if((Test-Path $downloadFolder) -eq $false)
{
Write-Output "Creating '$downloadFolder'..."
New-Item -ItemType Directory -Path $downloadFolder | Out-Null
}
# create a WebClient instance that will handle Network communications
$webClient = New-Object System.Net.WebClient
# original book: http://www.bl.uk/manuscripts/Viewer.aspx?ref=burney_ms_69_f001r
$baseUrl="http://www.bl.uk/manuscripts/Proxy.ashx?view="
$nameOfBook="burney_ms_69"
# install imagemagick for windows
# https://www.imagemagick.org/download/binaries/ImageMagick-7.0.7-23-Q16-x64-dll.exe
# pagenumbers go from f.1r, f.1v, f.2r, f.2v, ..... f.367r, f.367v
$pageIndeks=33
For($k=65; $k -le 734; $k++){
$pageNumber=""
$pageCharacter=""
$partall=
if($k % 2 -eq 0){ # if second-page/partall
$pageCharacter="v"
}else{ # oddetall
$pageCharacter="r"
}
if($pageIndeks -le 9){
$pageNumber="f00"+$pageIndeks
}elseif($pageIndeks -le 99){
$pageNumber="f0"+$pageIndeks
}elseif($pageIndeks -le 999){
$pageNumber="f"+$pageIndeks
}else{
$pageNumber="f"+$pageIndeks
}
$pageName=$pageNumber+$pageCharacter
Write-Output "Pagename is: "+$pageName
# iterate 21 times, but should really get this number from height of image from webpage
For ($i=0; $i -le 21; $i++){
$yAxisInfoText="Downloading small images for y-axis "+$i+" of page..."
Write-Output $yAxisInfoText
# iterate 26 times, but should get this number from width of image from webpage
For($j=0; $j -le 26; $j++){
# example of url: http://www.bl.uk/manuscripts/Proxy.ashx?view=burney_ms_69_f001r_files/12/3_5.jpg
$url = $baseUrl+$nameOfBook+"_"+$pageName+"_files/13/"+$i+"_"+$j+".jpg"
# create name of small image
if($i -gt 9 -and $j -gt 9){
$imgFile = "I_"+$i+"_"+$j+"_image_temp.jpg"
}elseif($i -gt 9 -and $j -le 9){
$imgFile = "I_"+$i+"_0"+$j+"_image_temp.jpg"
}elseif($i -le 9 -and $j -gt 9){
$imgFile = "I_0"+$i+"_"+$j+"_image_temp.jpg"
}else{
$imgFile = "I_0"+$i+"_0"+$j+"_image_temp.jpg"
}
# Write-Output "Downloading image from url: "+$url+" to image: "+$imgFile
# download small image
$imgSaveDestination = Join-Path $downloadFolder $imgFile
Write-Output "Downloading '$url' to '$imgSaveDestination'..."
$webClient.DownloadFile($url, $imgSaveDestination)
}
# Get y-axis pictures to append. They all have to have the same y-axis
if($i -gt 9){
$verticalImagesName="I_"+$i+"_`*_image_temp.jpg"
}else{
$verticalImagesName="I_0"+$i+"_`*_image_temp.jpg"
}
$verticalImagesPathAndName=Join-Path $downloadFolder $verticalImagesName
if($i -gt 9){
$verticalAppendedImageName="out_"+$i+"_temp.jpg"
}else{
$verticalAppendedImageName="out_0"+$i+"_temp.jpg"
}
$verticalAppendedImagesPath=Join-Path $downloadFolder $verticalAppendedImageName
Write-Output "Appending all vertical images to eachother..."
# imagemagick.exe command, Only works if imagemagick is in PATH
# Appends all images with same y-axis values togheter vertical
magick convert -append $verticalImagesPathAndName $verticalAppendedImagesPath
}
$horizontalImage="Page_"+$k+"_"+$pageName+".jpg"
if($k %2 -eq 0){
$pageIndeks++
}
$finalImagePath=Join-Path $downloadFolder $horizontalImage
$allVerticalImagesName="out_`*_temp.jpg"
$allVerticalImagesNamePath=Join-Path $downloadFolder $allVerticalImagesName
Write-Output "Appending all horizontal images to eachother..."
magick convert +append $allVerticalImagesNamePath $finalImagePath
$allFilesInDownloadFolder=$downloadFolder+"\*"
Write-Output "Removing all temporary pictures..."
Remove-Item -Path $allFilesInDownloadFolder -include *temp.jpg
} # page-loop ends