# decide to store or remove the image
if (isset($data['localImage'])) {
$image = ABSOLUTE_PATH . '/' . LOCAL_STORAGE . '/thumbnail-' . $this->_data['hash'].'.jpg';
+ if(DEBUG) {
+ error_log("DEBUG Try to save local image to: $image");
+ }
if ($data['localImage'] === true) {
+ if(DEBUG) {
+ error_log("DEBUG want to save local image to: $image");
+ }
if (!file_exists($image) || $_imageUrlChanged === true) {
+ if(DEBUG) {
+ error_log("DEBUG Image new or not there yet: $image");
+ }
Summoner::downloadFile($data['image'], $image);
}
} elseif ($data['localImage'] === false) {
+ if(DEBUG) {
+ error_log("DEBUG Image to be removed: $image");
+ }
if (file_exists($image)) {
unlink($image);
}
public function doSnapshot(string $url, string $filename): bool {
$ret = false;
- // new path in jason
- // lighthouseResult audits full-page-screenshot details screenshot data (base64 encoded)
-
if(!empty($url) && is_writable(dirname($filename))) {
+ if(DEBUG) {
+ error_log("DEBUG try to save to $filename with $this->_googlePageSpeed for $url");
+ }
$theCall = Summoner::curlCall($this->_googlePageSpeed.urlencode($url).'&screenshot=true');
if(!empty($theCall)) {
$jsonData = json_decode($theCall,true);
- if(!empty($jsonData) && isset($jsonData['screenshot']['data'])) {
- $imageData = $jsonData['screenshot']['data'];
- $imageData = str_replace(['_', '-'], ['/', '+'], $imageData);
- $imageData = base64_decode($imageData);
- $ret = file_put_contents($filename, $imageData);
+ if(DEBUG) {
+ error_log("DEBUG Call result data: ".var_export($jsonData, true));
+ }
+ if(!empty($jsonData) && isset($jsonData['lighthouseResult']['audits']['full-page-screenshot']['details']['screenshot']['data'])) {
+ $imageData = $jsonData['lighthouseResult']['audits']['full-page-screenshot']['details']['screenshot']['data'];
+
+ $source = fopen($imageData, 'r');
+ $destination = fopen($filename, 'w');
+ if(stream_copy_to_stream($source, $destination)) {
+ $ret = $filename;
+ }
+ fclose($source);
+ fclose($destination);
+ } elseif(DEBUG) {
+ error_log("DEBUG invalid json data. Path ['lighthouseResult']['audits']['full-page-screenshot']['details']['screenshot']['data'] not found in : ".var_export($jsonData, true));
}
+ } elseif(DEBUG) {
+ error_log("DEBUG curl call failed");
}
}
curl_setopt($ch, CURLOPT_USERAGENT,self::BROWSER_AGENT_STRING);
// curl_setopt($ch, CURLOPT_VERBOSE, true);
- //curl_setopt($ch, CURLOPT_HEADER, true);
+ // curl_setopt($ch, CURLOPT_HEADER, true);
if(!empty($port)) {
curl_setopt($ch, CURLOPT_PORT, $port);