This repository was archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathimage_extract.pl
More file actions
46 lines (36 loc) · 1.33 KB
/
image_extract.pl
File metadata and controls
46 lines (36 loc) · 1.33 KB
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
#!/usr/bin/perl -w
############################################################################
#
# AlchemyAPI Perl Example: Image Extraction
# Author: Orchestr8, LLC
# Copyright (C) 2009-2010, Orchestr8, LLC.
#
############################################################################
use strict;
use AlchemyAPI;
# Create the AlchemyAPI object.
my $alchemyObj = new AlchemyAPI();
# Load the API key from disk.
if ($alchemyObj->LoadKey("api_key.txt") eq "error")
{
die "Error loading API key. Edit api_key.txt and insert your API key.";
}
my $result = '';
my $imageParams = new AlchemyAPI_ImageParams();
# Get the image from a URL, using the more CPU intensive (and more accurate) approach
$imageParams->SetExtractMode("always-infer");
$result = $alchemyObj->URLGetImage("http://www.umich.edu/", $imageParams);
printf $result;
# Get the image from a URL, using the less CPU intensive (and less accurate) approach
$imageParams->SetExtractMode("trust-metadata");
$result = $alchemyObj->URLGetImage("http://www.umich.edu/", $imageParams);
printf $result;
# Load an example HTML file to analyze
my $HTMLFile;
my $HTMLContent;
open($HTMLFile, "data/example.html");
sysread($HTMLFile, $HTMLContent, -s($HTMLFile));
close($HTMLFile);
# Get that image
$result = $alchemyObj->HTMLGetImage($HTMLContent, "http://www.test.com/", $imageParams);
printf $result