Created
December 31, 2013 10:58
-
-
Save orzFly/8195268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$asins = $argv; array_shift($asins); | |
function fetch_amazon_jp_images($asin) | |
{ | |
$opts = array( | |
'http'=>array( | |
'method'=>"GET", | |
'header'=>"User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" | |
) | |
); | |
$context = stream_context_create($opts); | |
echo "downloading $asin...\n"; | |
$body = file_get_contents("http://www.amazon.co.jp/gp/product/images/$asin", false, $context); | |
if (preg_match_all("|var scaleLevels;([^<]*?)//-->|s", $body, $matches, PREG_SET_ORDER)) | |
{ | |
foreach($matches as $match) | |
{ | |
$m = $match[1]; | |
preg_match_all("|scaleLevels\\[(?P<level>\d+)\\] = new MediaServicesZoomScale\\((?P<width>\d+), (?P<height>\d+), (?P<slice>\d+)\\);|", $m, $levels, PREG_SET_ORDER); | |
$l = $levels[count($levels) - 1]; | |
list($width, $height, $slice, $level) = array($l["width"], $l["height"], $l["slice"], $l["level"]); | |
$ws = ceil($width / $slice); | |
$hs = ceil($height / $slice); | |
$huge = ImageCreateTrueColor($width, $height); | |
for ($x = 0; $x < $ws; $x ++) | |
{ | |
for ($y = 0; $y < $hs; $y ++) | |
{ | |
echo "-> drawing ($x, $y) of ($ws, $hs)...\n"; | |
$part = ImageCreateFromJPEG("http://z2-ec2.images-amazon.com/R/1/a=$asin+d=_SCR($level,$x,$y)_+e=.jpg"); | |
ImageCopy($huge, $part, $x * $slice, $y * $slice, 0, 0, ImageSX($part), ImageSY($part)); | |
ImageDestroy($part); | |
} | |
} | |
echo "-> compling...\n"; | |
ImagePNG($huge, "$asin.png"); | |
} | |
} | |
} | |
foreach($asins as $asin) | |
{ | |
fetch_amazon_jp_images($asin); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment