I'm looking into what is slowing some scripts of mine down. I have got the following scripts, essentially the same, the only difference is one is in a subfolder and uses $_SERVER['DOCUMENT_ROOT'] to get the image url.
Script 1 (C:/xampp/htdocs/ppa/test.php):
<?php
$time_start = microtime(true);
ini_set("memory_limit", -1);
$im = imagecreatefromjpeg("data/images/20140310/4/test.jpg");
$ratio = 500 / imagesx($im);
$width = 500;
$height = imagesy($im) * $ratio;
//Create thumbnail container
$thumb = imagecreatetruecolor($width,$height);
imagecopyresampled($thumb,$im,0,0,0,0,$width,$height,imagesx($im),imagesy($im));
$time_end = microtime(true);
$execution_time = "Took ".($time_end - $time_start)/60 ." to generate image";
$white = imagecolorallocate($im,255,255,255);
$font = "images/fonts/Calibri Bold.ttf";
imagettftext($thumb,15,0,20,20,$white,$font,$execution_time);
header("Content-Type: image/jpeg");
imagejpeg($thumb,"thumb.jpg",100);
imagedestroy($im);
?>
Here is the image it produces with the time it took on it:
Script 2 (C:/xampp/htdocs/ppa/benchmarking/generate_thumb.php):
<?php
$time_start = microtime(true);
ini_set("memory_limit", -1);
$im = imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT']."/ppa/data/images/20140310/4/test.jpg");
$ratio = 500 / imagesx($im);
$width = 500;
$height = imagesy($im) * $ratio;
//Create thumbnail container
$thumb = imagecreatetruecolor($width,$height);
imagecopyresampled($thumb,$im,0,0,0,0,$width,$height,imagesx($im),imagesy($im));
$time_end = microtime(true);
$execution_time = "Took ".($time_end - $time_start)/60 ." to generate image";
$white = imagecolorallocate($im,255,255,255);
$font = $_SERVER['DOCUMENT_ROOT']."/ppa/images/fonts/Calibri Bold.ttf";
imagettftext($thumb,15,0,20,20,$white,$font,$execution_time);
header("Content-Type: image/jpeg");
imagejpeg($thumb,"thumb.jpg",100);
imagedestroy($im);
?>
Image it produces:
The times stay similar every time, why is it quicker in the sub directory!? Downsizing from a 1.15MB image (4512x3000)