<?php function makeThumb ($fileUrl, $moveDir, $fileSize){ if($width > $height){ $max = $width; $min = $height; } if($width <= $height){ $max = $height; $min = $width; } $rate = $max/$fileSize; $final_x = $width/$rate; $final_y = $height/$rate; if($final_x > $width) { $final_x = $width; $final_y = $height; } $image_p = imagecreatetruecolor($final_x, $final_y); $image = imagecreatefromjpeg($fileUrl); $finalImg = imagecopyresampled($image_p, $image, 0, 0, 0, 0, $final_x, $final_y, $width, $height); imagejpeg($finalImg, $moveDir, 70); imagedestroy($image_p); imagedestroy($image); } makeThumb('../tmp/0000001.jpg', './images/', 640); ?>
Ma on za zadanie przekonwertowanie obrazka z tmp/0000001.jpg do images/0000001.jpg o mniejszych wymiarach.
Układ plików wygląda następująco:
Kod
+ admin
- index.php
+ images
+ tmp
- 0000001.jpg
- index.php
+ images
+ tmp
- 0000001.jpg
A interpreter php zwraca:
Kod
Warning: imagejpeg(): supplied argument is not a valid Image resource in /admin/index.php on line 33
Co tu nie gra i jak to poprawić?