function rmtry($f) { if (ufile_exists($f)) { @uunlink($f); } }
mylock($thash) || exit; if (!ufile_exists($CFG['tempdir'] . $thash . '.png')) { while (ufile_exists($CFG['tempdir'] . 'firefox.lock')) { sleep(rand(5, 15)); } utouch($CFG['tempdir'] . 'firefox' . '.lock'); file_put_contents($CFG['tempdir'] . 'firefox' . '.lock', $thash); $cmd = $firefox . ' -no-remote -profile ' . escapeshellarg($ffprofile) . ' -saveimage ' . escapeshellarg('file:///' . r(urealpath($rootdir . $file))) . ' -savedelay 100 -witdh 1024'; #logger($cmd); exe($cmd); ucopy($ffdownload . 'shot.png', $CFG['tempdir'] . $thash . '.png'); uunlink($ffdownload . 'shot.png'); uunlink($CFG['tempdir'] . 'firefox' . '.lock'); $cmd = $imagemagick_identify . ' -format "%wx%h" ' . escapeshellarg($CFG['tempdir'] . $thash . '.png'); list($w, $h) = explode('x', trim(exe($cmd))); $A4 = 297 / 210; if ($h / $w > $A4) { $h = intval($w * $A4); ucopy($CFG['tempdir'] . $thash . '.png', $CFG['tempdir'] . $thash . '_0.png'); uunlink($CFG['tempdir'] . $thash . '.png'); $cmd = $imagemagick_convert . ' -crop "' . $w . 'x' . $h . '+0+0" ' . escapeshellarg($CFG['tempdir'] . $thash . '_0.png') . ' ' . escapeshellarg($CFG['tempdir'] . $thash . '.png'); exe($cmd); uunlink($CFG['tempdir'] . $thash . '_0.png'); } } $cmd = $imagemagick_convert . ' -quality 70 -geometry ' . $size . ' ' . escapeshellarg($CFG['tempdir'] . $thash . '.png') . ' ' . escapeshellarg($CFG['cachedir'] . $hash . '_' . $size . '.jpg'); exe($cmd); rmtry($CFG['tempdir'] . $thash . '.png'); myunlock($thash); } }