本人想截取一类图片的一个区域  
  在网上也找过几个图片处理的类  
   但是都不好用 
特此 求得一个截取文件 
   原来自己写的文件 总是在 imagecreatefromjpeg 后 报内存错误    

解决方案 »

  1.   

    gd就能截了。imagecopyresized — Copy and resize part of an imageDescriptionbool imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
    imagecopyresized() copies a rectangular portion of one image to another image. dst_image is the destination image, src_image is the source image identifier.In other words, imagecopyresized() will take an rectangular area from src_image of width src_w and height src_h at position (src_x,src_y) and place it in a rectangular area of dst_image of width dst_w and height dst_h at position (dst_x,dst_y).If the source and destination coordinates and width and heights differ, appropriate stretching or shrinking of the image fragment will be performed. The coordinates refer to the upper left corner. This function can be used to copy regions within the same image (if dst_image is the same as src_image) but if the regions overlap the results will be unpredictable.<?php
    // File and new size
    $filename = 'test.jpg';
    $percent = 0.5;// Content type
    header('Content-Type: image/jpeg');// Get new sizes
    list($width, $height) = getimagesize($filename);
    $newwidth = $width * $percent;
    $newheight = $height * $percent;// Load
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    $source = imagecreatefromjpeg($filename);// Resize
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);// Output
    imagejpeg($thumb);
    ?>
      

  2.   

    $url = 'http://avatar.profile.csdn.net/F/C/1/2_hongsige1989.jpg';
    $s = file_get_contents($url);
    $ims = imagecreatefromstring($s);$w = imagesx($ims);
    $h = imagesy($ims);$imd = imagecreatetruecolor($w/2, $h/2);
    imagecopy($imd, $ims, 0, 0, $w/4, $h/4, $w/2, $h/2);
     
    imagepng($imd);