Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating virtual thumbnail of image with PHP
    text
    copied!<p>I want to display the thumbnail of image while displaying time,but dont want to save the image.</p> <p>I have tried some <code>notorious ;)</code> script but its not working :(. Please have look and let me know do you have any idea</p> <pre><code>&lt;?php function print_thumb($src, $desired_width = 100){ /* read the source image */ $source_image = imagecreatefromjpeg($src); $width = imagesx($source_image); $height = imagesy($source_image); /* find the "desired height" of this thumbnail, relative to the desired width */ $desired_height = floor($height * ($desired_width / $width)); /* create a new, "virtual" image */ $virtual_image = imagecreatetruecolor($desired_width, $desired_height); /* copy source image at a resized size */ imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height); // Set the content type header - in this case image/jpeg header('Content-Type: image/jpeg'); // Output the image imagejpeg($virtual_image); } ?&gt; &lt;img src="&lt;?php print_thumb("s1.jpg"); ?&gt;" /&gt; </code></pre> <p>I saved this file as <code>thumbs.php</code> (single file) while accessing it via localhost it displaying like</p> <p><code>&lt;img src="http://localhost/test/thumbs.php"&gt;</code></p> <p>Its working fine if I write both in separate file.</p> <p>like <code>file.html</code> with </p> <p><code>&lt;img src="thumb.php?img=s1.jpg" /&gt;</code></p> <p>and</p> <p>thumb.php</p> <pre><code>&lt;?php function print_thumb($src, $desired_width = 100){ /* read the source image */ $source_image = imagecreatefromjpeg($src); $width = imagesx($source_image); $height = imagesy($source_image); /* find the "desired height" of this thumbnail, relative to the desired width */ $desired_height = floor($height * ($desired_width / $width)); /* create a new, "virtual" image */ $virtual_image = imagecreatetruecolor($desired_width, $desired_height); /* copy source image at a resized size */ imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height); // Set the content type header - in this case image/jpeg header('Content-Type: image/jpeg'); // Output the image imagejpeg($virtual_image); } print_thumb($_REQUEST['img']); ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload