Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

How to use the Sprite Scraper

Kell Evoy edited this page May 14, 2023 · 1 revision

Overview

The SpriteScraper module downloads images from the game's Wiki API. It can be used programmatically in your scripts, or through the OSBC user interface. The images retrieved by this utility are great for image searching, as they have transparent backgrounds and are cropped to the image's edges. Additionally, the tool allows for downloading pre-processed images suitable for searching within a bank/inventory interface; this removes the area of the image that could be overlapped by item stack numbers.

Table of Contents

Sprite Scraper via User Interface

Step 1: Launch OSBC and open the Sprite Scraper window

On the main page of the OSBC user interface, you will see a button labelled "Sprite Scraper". Clicking this button will open the Sprite Scraper window.

scraper_home_page

Step 2: Select the image type

The Sprite Scraper window has radio buttons for selecting the type of image you'd like to download. The options are:

  • Normal - Downloads the full image.
  • Bank - Downloads a cropped version of the image suitable for image search within a bank interface (i.e., removes item stack number area).
  • Normal + Bank - Downloads both versions of the image.

Select the image type you'd like to download. If you're not sure, select Normal + Bank.

Step 3: Enter item/spell/prayer name(s)

The Sprite Scraper window has a text box for entering the name of the item/spell/prayer you'd like to download. You can enter multiple names by separating them with a comma. For example, Abyssal whip, Dragon scimitar, Dragon dagger will download the sprites for all three items.

Your input doesn't have to be perfect. The utility will compensate for capitalization and spacing. For example, abyssal whip , and Abyssal Whip will both download the same image.

scraper

Step 4: Download and see the results

Click the Submit button and wait for the images to download. Once the download is complete, the tool will tell you where the images were saved.

scraper_search

Sprite Scraper via Code

You can also use the Sprite Scraper directly within your scripts. This is useful if you want to distribute a script, but don't want to include the images with it.

Step 1: Import the necessary classes and modules

First, you need to import the SpriteScraper class and the ImageType enumeration from the module.

from utilities.sprite_scraper import SpriteScraper, ImageType

Step 2: Create a SpriteScraper instance

Create an instance of the SpriteScraper class.

scraper = SpriteScraper()

Step 3: Search and download images

Use the search_and_download method to search for images and download them to a specified destination. This method takes a search string as its primary argument, and you can pass additional keyword arguments to modify its behavior.

In this example, we'll retrieve images for some Runes that can be used for bank searching. We want to save them to a folder called "runes" which we have not manually created.

search_string = "Water Rune, Fire Rune"
image_type = ImageType.BANK
destination = scraper.DEFAULT_DESTINATION.joinpath("runes")

path = scraper.search_and_download(
    search_string=search_string,
    image_type=image_type,
    destination=destination
    notify_callback=self.log_msg)

Here's a brief explanation of the keyword arguments used:

  • image_type - The type of image to save. Can be one of the following:
    • ImageType.NORMAL - Save normal images (default).
    • ImageType.BANK - Save bank images.
    • ImageType.ALL - Save both normal and bank images.
  • destination - The destination folder to save the images. Defaults to a folder named "scraper" inside the utilities.imagesearch.BOT_IMAGES path. If the path provided doesn't exist, it will be created.
  • notify_callback - An optional callback function used to notify the user of the progress. Defaults to the print function. The search_and_download method returns the destination folder where the images were saved.

Step 4: Access the results

Once that method completes, the path variable will point to the folder where the images were saved. The images are saved in the following format:

# Normal #
Capitalized_name.png

# Bank #
Capitalized_name_bank.png

For example, if you wanted to perform an image search for the Water Rune, you might do something like this:

import utilities.image_search as imsearch

# Assuming the scraper saved results to `path`
path = scraper...

# Locate water rune in your bank
water_rune_path = path.joinpath("Water_rune_bank.png")
water_rune = imsearch.search_img_in_rect(water_rune_path, self.win.game_view)
...