dimanche 12 avril 2015

Upgraded to php5.5 from 4.* and now thumbnail scripts aren't working

While I've been able to fix most of the issues on my website since the host upgraded to PHP 5.5, thumbnail scripts still aren't working. The script just loads images that have a "?" in Safari. Here's the server GD info:



array(12) { ["GD Version"]=> string(26) "bundled (2.1.0 compatible)" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["T1Lib Support"]=> bool(false) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPEG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XPM Support"]=> bool(false) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) }



Here's the script:



<?php

$dWidth = "130"; $dHeight = "100";

# Constants
// define(IMAGE_BASE, '../images/galleries');
define(MAX_WIDTH, $dWidth);
define(MAX_HEIGHT, $dHeight);

# Get image location
$image_file = str_replace('..', '', $file);
$image_path = IMAGE_BASE . "/$image_file";

# Load image
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($image_path);
} else if ($ext == 'png') {
$img = @imagecreatefrompng($image_path);
}

# If an image was successfully loaded, test the image for size
if ($img) {

# Get image size and scale ratio
$width = imagesx($img);
$height = imagesy($img);
$scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height);

# If the image is larger than the max shrink it
if ($scale < 1) {
$new_width = floor($scale*$width);
$new_height = floor($scale*$height);

# Create a new temporary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);

imagealphablending( $tmp_img, false );
imagesavealpha( $tmp_img, true );

# Copy and resize old image into new image
imagecopyresized($tmp_img, $img, 0, 0, 0, 0,
$new_width, $new_height, $width, $height);
imagedestroy($img);
$img = $tmp_img;

}
}

# Create error image if necessary
if (!$img) {
echo "No Preview Available";
}

# Display the image
header("Content-type: image/png");
imagepng($img);

?>

Aucun commentaire:

Enregistrer un commentaire