Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Ok so this is my updated thumbnail.php file, feel free to use:

    <?php
    
    	$s = '';
    	$w = 0;
    	$h = 0;
    	if (isset($_GET['s'])) {
    		$s = filter_var(trim($_GET['s']), FILTER_VALIDATE_URL);
    		if ( ! $s ) { // haven't got a valid URL file so give up now..
    			echo 'FATAL EXCEPTION: Not a valid file';
    			die();
    		}
    	}
    	if (isset($_GET['w'])) {
    		$w = filter_var(trim($_GET['w']), FILTER_VALIDATE_INT);
    	}
    	if (isset($_GET['h'])) {
    		$h = filter_var(trim($_GET['h']), FILTER_VALIDATE_INT);
    	}
    
    	// if we don't have BOTH dimensions
    	// default to actual image (direct, no need to start creating images, huh?)
    	// otherwise we could end up with mis-shaped image
    	if ( ! ( $w && $w > 0 )
    			|| ! ($h && $h > 0 ) ) {
    		header('Location: ' . $s);
    		die();
    	}
    
    	$image_type = exif_imagetype($s);
    
    	switch($image_type) {
    		case IMAGETYPE_JPEG: $src = imagecreatefromjpeg($s); break;
    		case IMAGETYPE_GIF: $src = imagecreatefromgif($s); break;
    		case IMAGETYPE_PNG: $src = imagecreatefrompng($s); break;
    		default:
    			echo "Exif problem : exif_imagetype('$s') returned '" . (!$image_type ? 'FALSE' : $image_type) . "' <br/>";
    			echo "<pre>";print_r(gd_info());echo "</pre>";
    			echo "Aborting<br/>";
    			exit();
    	}
    
    	header("Content-type: {$image_type}");
    
    	list($width, $height) = getimagesize($s);
    
    	$thumb = imagecreatetruecolor($w, $h);
    	imagecopyresampled($thumb, $src, 0, 0, 0, 0, $w, $h, $width, $height);
    	imagejpeg($thumb);
    	imagedestroy($thumb);
    	imagedestroy($src);
    
    ?>

    For what it’s worth, I don’t think GD is the problem (entirely).

    The thumbnail.php uses undefined variables. One of them, $s, is used in the exif_imagetype() function call. This is why you see the error “Warning: exif_imagetype(): Filename cannot be empty in…” – the code is actually outputting the value of $s in this error message but since $s is not defined we’re not seeing it.

    You can add

    $s = $_GET[‘s’];
    $w = $_GET[‘w’];
    $h = $_GET[‘h’];

    to the top of your file and that should fix your thumbnail issues. That said, that’s very loose and assuming those params are always going to be used when accessing thumbnail.php.

    Hopefully it will get you on the right track.

Viewing 2 replies - 1 through 2 (of 2 total)