stevesimo Posted August 14, 2008 Share Posted August 14, 2008 Hi, I am having difficuly using the imagecopy command. I have a large image and I am trying to copy a small area of this image and save this to a file. However I cant get it to work and am not sure where I am going wrong. Here is my code $imagefile = 'largeimage.png'; $src = imagecreatefrompng($imagefile); $dest = imagecreatetruecolor(83, 24); // Copy small image from large image imagecopy($dest, $imagefile, 358, 70, 0, 0, 83, 24); $image = 'smallimage.png'; $newimage = @imagecreatefrompng($dest); imagepng($newimage, $image, 75); imagedestroy($newimage); The main part of what I am trying to do is not just to copy the image but actually saving it to a file. Can anyone point me in the right direction. Thanks, Steve (Blackpool, UK) Link to comment https://forums.phpfreaks.com/topic/119641-problem-using-imagecopy/ Share on other sites More sharing options...
Barand Posted August 14, 2008 Share Posted August 14, 2008 $imagefile = 'largeimage.png'; $src = imagecreatefrompng($imagefile); $dest = imagecreatetruecolor(83, 24); // Copy small image from large image imagecopy($dest, $imagefile, 358, 70, 0, 0, 83, 24); $image = 'smallimage.png'; imagepng($dest, $image, 75); imagedestroy($src); imagedestroy($dest); Link to comment https://forums.phpfreaks.com/topic/119641-problem-using-imagecopy/#findComment-616389 Share on other sites More sharing options...
stevesimo Posted August 14, 2008 Author Share Posted August 14, 2008 hi, thanks for your code, i have uploaded it and it seems to run ok, however when I try and access the small image which has been created, my browser simply displays the path of the image, not the image itself. Do you have any ideas as to what this might be? Thanks Steve Link to comment https://forums.phpfreaks.com/topic/119641-problem-using-imagecopy/#findComment-616393 Share on other sites More sharing options...
stevesimo Posted August 14, 2008 Author Share Posted August 14, 2008 I removed the 75 of the imagepng command and now the image displays but simply as a black rectangle. Could this be because my image coords are incorrect? Link to comment https://forums.phpfreaks.com/topic/119641-problem-using-imagecopy/#findComment-616397 Share on other sites More sharing options...
Barand Posted August 14, 2008 Share Posted August 14, 2008 Sorry, missed that one imagecopy($dest, $src, 0, 0, 358, 70, 83, 24); Link to comment https://forums.phpfreaks.com/topic/119641-problem-using-imagecopy/#findComment-616730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.