Det verkar som om allt utom att skriva filen till disken fungerar. Jag har provat att sätta chmod 777 på alla filer, men det gjorde ingen skillnad, och det borde det väl inte heller. Någon som hittar något uppenbart fel?
Code: Select all
<?php
/* User defined variables */
$source_file = "./test.jpg";
$destination_file = "./thumb_test.jpg";
$new_width = 400;
/* Check if above variables seems OK */
print "Source: $source_file<BR>";
print "Destination: $destination_file<BR>";
/* Create image resource from old file */
$source_image = imagecreatefromjpeg($source_file);
/* Get old image size */
$old_width = imagesx($source_image);
$old_height = imagesy($source_image);
$aspect = $old_width/$old_height;
/* Calculate new image size */
$new_height = $new_width/$aspect;
/* Create new image resource */
$destination_image = imagecreatetruecolor($new_width,$new_height);
$created_width = imagesx($destination_image);
$created_height = imagesy($destination_image);
/* Check if above calculations worked as expected */
print "Original width: $old_width<BR>";
print "Original height: $old_height<BR>";
print "Thumbnail width: $new_width<BR>";
print "Thumbnail height: ".(int)$new_height."<BR>";
print "Created thumbnail width: $created_width <BR>";
print "Created thumbnail height: $created_height <BR>";
print "Aspect: $aspect<BR>";
/* Resize source image to the new image resource with the values calculated above */
imagecopyresized($destination_image, $source_image, 0, 0, 0, 0, $new_width, (int)$new_height, $old_width, $old_height);
/* Write thumbnail to disk */
imagejpeg($destination_image, $destination_file, 100);
/* Destroy image resources */
imagedestroy($source_image);
imagedestroy($destination_image);
?>
Source: ./test.jpg
Destination: ./thumb_test.jpg
Original width: 1280
Original height: 960
Thumbnail width: 400
Thumbnail height: 300
Created thumbnail width: 400
Created thumbnail height: 300
Aspect: 1.3333333333333