How to get a permanent link of the images in a book on Archive.org

How to get a permanent link of the images in a book on Archive.org

If you get a link of the book pages from archive.org it will look like this

https://ia902207.us.archive.org/BookReader/BookReaderImages.php?zip=/29/items/whitenightsother00dostiala/whitenightsother00dostiala_jp2.zip&file=whitenightsother00dostiala_jp2/whitenightsother00dostiala_0009.jp2&id=whitenightsother00dostiala&scale=4&rotate=0

Now this link is not permanent and can change with time

here is how the permanent link will look like

https://archive.org/download/whitenightsother00dostiala/whitenightsother00dostiala_jp2.zip/whitenightsother00dostiala_jp2/whitenightsother00dostiala_0009.jp2&ext=jpg

to get a permanent link you can use this Javascript code

<p>
<input type="search" id="link" style="width: 100%; padding:15px;"/>
</p>
<p>
<button onclick="getPermanentLink()">Get Permanent Link</button>
</p>
<img id='testImg' src='' width=100 />
function getPermanentLink() {
            const basicLink = document.querySelector('#link').value;
            const parts = basicLink.split('/items/');
            const parts2 = parts[1].split('&id=');
            let imgLink = parts2[0];
            imgLink = imgLink.replace('&file=', '/');
            const readyLink = `https://archive.org/download/${imgLink}&ext=jpg`;
            const imgEl = document.querySelector('#testImg');
            imgEl.src = '';
            imgEl.src = readyLink;

        }

This is how you can get link using php

 $link = "https://ia902207.us.archive.org/BookReader/BookReaderImages.php?zip=/29/items/whitenightsother00dostiala/whitenightsother00dostiala_jp2.zip&file=whitenightsother00dostiala_jp2/whitenightsother00dostiala_0009.jp2&id=whitenightsother00dostiala&scale=4&rotate=0";
        $parts = explode('/items/', $link);
        $parts2 = explode('&id=', $parts[1]);
        $imgLink = $parts2[0];
        $imgLink = str_replace('&file=', '/', $imgLink);
        $readyLink = 'https://archive.org/download/' . $imgLink . '&ext=jpg';

        echo "<img id='testImg' src='$readyLink' width=300/>";

Leave a Comment

Scroll to Top