-
Notifications
You must be signed in to change notification settings - Fork 141
How to use the Sprite Scraper
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.
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.
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.
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.
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.
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.
First, you need to import the SpriteScraper
class and the ImageType
enumeration from the module.
from utilities.sprite_scraper import SpriteScraper, ImageType
Create an instance of the SpriteScraper
class.
scraper = SpriteScraper()
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.
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)
...