Jump to content

Problem using imagecopy


stevesimo

Recommended Posts

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

  $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);

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.