Hi, i made an image resizer in php. When an image is resized, it caches a new jpg file with the new dimensions. Next time you call the exact img.php?file=hello.jpg&size=400 it checks if the new jpg has already been created.
- If it has NOT been created yet, it creates the file and then prints the output (cool).
- If it ALREADY exists, no new file needs to be generated and instead, it just calls the already cached file.
My question is regarding the second scenario. Which of these is faster?
- redirecting:
header('Location: cache/hello_400.jpg');die();
- grabbing data and printing the cached file:
$data = file_get_contents('cache/hello_400.jpg'); header('Content-type: '.$mime); header('Content-Length: '.strlen($data)); echo $data;
Any other ways to improve this?
If someone wants the generated code, check this out: http://egobits.com/misc/img.phps
Thanks to all for the help!