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\d+)\\] = new MediaServicesZoomScale\\((?P\d+), (?P\d+), (?P\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); }