Page 1 of 1

What is a valid image resource for imagecopyresample()

Posted: Thu Apr 08, 2004 9:13 pm
by sethpackham
First, let me paste the warning that I'm getting:
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/<mypath>/journal_submit.php on line 69

I'm trying to understand how to get an image on my filesystem to be used as a valid resource for imagecopyresample() so I can resize it. I haven't been able to get the image recognized as a resource. I read the documentation on php.net on resources, and it says that imagecreatefromjpeg() creates a valid resource that is used by imagecopyresample(), but it doesn't look like it's working for me. This is my first time trying these functions, so maybe I just don't get it.

I'm not an expert, but I do my homework and try to learn one function at a time. This one has stumped me.

Code: Select all

<?php
//some variables for my imagecopyresample()
//the server path to my existing image, which I just uploaded and moved here using a form and move_uploaded_file()
$img_src = $photos_path.$realphotoname; 
//where I want to copy it and resize it to
$img_dest = $photos_path.$realphotoname.$thumbstring;

//Trying to make my image a resource that can be resampled
$img_resource = imagecreatefromjpeg($img_src);

//Just a test to see what gets returned. Maybe I don't understand resource.
echo $img_resource;
//That outputs: "Resource id #21"

//imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH
imagecopyresampled($img_dest, $img_resource, 0, 0, 0, 0, 64, 48, 640, 480);// or die(mysql_error);
?>
Anyone have any ideas to help me? Thanks!

Posted: Thu Apr 08, 2004 9:18 pm
by markl999
The first 2 arguments to imagecopyresampled() have to be image resources, in your example the second argument is one, but $img_dest is just a string.
The user comments at http://php.net/imagecopyresampled provide some decent examples of using it, but if you still get stuck then ask back again ;)

Posted: Thu Apr 08, 2004 11:31 pm
by sethpackham
OK, that gets me a little further. The imagecopyresized and imagecopyresampled both like my resources now, but no resizing seems to be happening. The examples on php.net seem just like more complex functions doing the same thing I'm trying to do here. I want to understand why my code is not doing what I think it should be doing, then I can start expanding it for conditions, etc.

Code: Select all

<?php
//Two string variables for images
$img_src = $nails_photos_path.$realphotoname;
$img_dest = $nails_photos_path.$thumbstring.$realphotoname;

//copy the one image and make another with prefix "thumb_" // This part works
copy($img_src, $img_dest);

//this part also works
$img_full = imagecreatefromjpeg($img_src);
$img_thumb = imagecreatefromjpeg($img_dest);

//none of these do any resizing of above resources
//imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
//imagecopyresampled($img_thumb, $img_full, 0, 0, 0, 0, 64, 48, 640, 480) or die(mysql_error);
imagecopyresized($img_thumb, $img_full, 0, 0, 0, 0, 100, 75, 640, 480) or die(mysql_error);
?>
The one thing I did just notice is that the file that results from my copy() has different permissions on it (the thumbnail). Maybe that's why the resize isn't doing anything?
-rw------- 1 www wheel 68134 Apr 9 04:27 test_nails.jpg
-rw-r--r-- 1 www www 68134 Apr 9 04:27 thumb_test_nails.jpg