自动调整php中​​的图像大小

I tested my site at google page speed they suggested me to serve images rescaled.

Right now for thumbnail I'm using this php

<?php 
if($ad_thumbnails) 
{ 
    if ($row['picfile']) $picfile = "{$datadir[adpics]}/{$row[picfile]}";

    else $picfile = "images/noimage2.png";

    $imgsize = GetThumbnailSize($picfile, $tinythumb_max_width, $tinythumb_max_height);
?>

What will be the best practice to rescale images automatically by modifying above code?

There are tons of full-blown examples on how to resize images in php. Essentially you'll need the GD2 image processing library enabled at your web server, and you'll need to use

  1. imagecreatefromjpeg (or imagecreatefrompng or imagecreatefromgif) to create an image resource form your original file

  2. imagecreatetruecolor to create a new canvas for your thumbnail (with the desired thumbnail dimensions)

  3. imagecopyresampled to create the resized version of you original image on your new canvas

Here is a fully working example. Or, if you're lazy :) look at this drag&drop solution, that will do smart image resizing and caching only via URL parsing.