0

I am trying to save PhpThumb output. As what I could find on-line was not sufficient or too complex, I would like to ask if any one knows how to it?

$thumb_src="\"phpThumb/phpThumb.php?src=../apartmentsPhotos/".$num['ref']."/1.JPG&h=119&q=100\"";

echo" '<'img src=".$thumb_src />";

So what I want to do is to save the img src into an Image.

(So far I was creating the thumbnails on the fly but it seems that google and my web server don´t like it too much. Saving the thumbnails will ensure that in no time I will have all my thumbnails in real files and then I will use this function just for new content.)

hakre
  • 193,403
  • 52
  • 435
  • 836
ori
  • 43
  • 1
  • 5

2 Answers2

1

From phpThumb's FAQ

The best way is to call phpThumb as an object and call RenderToFile() to save the thumbnail to whatever filename you want. See /demo/phpThumb.demo.object.php for an example. The other way is to use the 'file' parameter (see /docs/phpthumb.readme.txt) but this parameter is deprecated and does not work in phpThumb v1.7.5 and newer.

Kevin
  • 53,822
  • 15
  • 101
  • 132
skovrec
  • 131
  • 1
  • 1
  • 11
0

Once you have generated the URL with this line you posted:

$thumb_src="\"phpThumb/phpThumb.php?src=../apartmentsPhotos/".$num['ref']."/1.JPG&h=119&q=100\"";

Pass it as a $_GET variable to another page, call it serveThumb.php:

if (!isset($_GET['img']))
      exit;

header('Content-type: application/pdf');
echo file_get_contents($_GET['img']);

You might have to add your own validation to serveThumb.php. Now you can save the result of serveThumb.php as a JPG.

Alternatively, save the contents of the image as a JPG file.

if (!isset($_GET['img']))
      exit;

$img = file_get_contents($_GET['img']);
file_put_contents("myImage.jpg", $img);
Chris Laplante
  • 29,338
  • 17
  • 103
  • 134