I have the following script to resize and crop images. I can use jpg and png files, but can't use tif files. Can you please help?

<?php
function Image($image, $crop = null, $size = null) {
    $image = ImageCreateFromString(file_get_contents($image));

    if (is_resource($image) === true) {
        $x = 0;
        $y = 0;
        $width = imagesx($image);
        $height = imagesy($image);

        /*
        CROP (Aspect Ratio) Section
        */

        if (is_null($crop) === true) {
            $crop = array($width, $height);
        } else {
            $crop = array_filter(explode(':', $crop));

            if (empty($crop) === true) {
                    $crop = array($width, $height);
            } else {
                if ((empty($crop[0]) === true) || (is_numeric($crop[0]) === false)) {
                        $crop[0] = $crop[1];
                } else if ((empty($crop[1]) === true) || (is_numeric($crop[1]) === false)) {
                        $crop[1] = $crop[0];
                }
            }

            $ratio = array(0 => $width / $height, 1 => $crop[0] / $crop[1]);

            if ($ratio[0] > $ratio[1]) {
                $width = $height * $ratio[1];
                $x = (imagesx($image) - $width) / 2;
            }

            else if ($ratio[0] < $ratio[1]) {
                $height = $width / $ratio[1];
                $y = (imagesy($image) - $height) / 2;
            }

        }

        /*
        Resize Section
        */

        if (is_null($size) === true) {
            $size = array($width, $height);
        }

        else {
            $size = array_filter(explode('x', $size));

            if (empty($size) === true) {
                    $size = array(imagesx($image), imagesy($image));
            } else {
                if ((empty($size[0]) === true) || (is_numeric($size[0]) === false)) {
                        $size[0] = round($size[1] * $width / $height);
                } else if ((empty($size[1]) === true) || (is_numeric($size[1]) === false)) {
                        $size[1] = round($size[0] * $height / $width);
                }
            }
        }

       $result = ImageCreateTrueColor($size[0], $size[1]);

        if (is_resource($result) === true) {
            ImageSaveAlpha($result, true);
            ImageAlphaBlending($result, true);
            ImageFill($result, 0, 0, ImageColorAllocate($result, 255, 255, 255));            
            ImageCopyResampled($result, $image, 0, 0, $x, $y, $size[0], $size[1], $width, $height);
            
			$white = imagecolorallocatealpha($result, 255, 255, 255, 60);
			$blue = imagecolorallocatealpha($result, 0, 103, 255, 60);
			$black = imagecolorallocatealpha($result, 0, 0, 0, 60);
			imagelayereffect($result,IMG_EFFECT_ALPHABLEND);
			imagesetthickness  ($result,2);
            imagerectangle($result, 1, 1, $size[0]-2, $size[1]-2, $black);
            ImageInterlace($result, true);
            ImageJPEG($result, null, 90);
             
        }
    }

    return false;
}
if (!isset($_GET['size']))
{
	$size = 150;
}
else
{
	$size = $_GET['size'];
}
header('Content-Type: image/jpeg');
Image("$_GET[img]", "1:1", "$size"."x");
imagedestroy($result);
?>

You can call this script bij: filename.php?img=img_location

Actually that is not solving my problem.
I want to resize and crop a tif-file..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.