Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   PHP, PERL, MySQL, JavaScript (https://forum.antichat.xyz/forumdisplay.php?f=37)
-   -   вопрос по GD (https://forum.antichat.xyz/showthread.php?t=96621)

SYMBiO 16.12.2008 05:25

вопрос по GD
 
как из картинки вырезать область по координатам?
вопрос конечно... маны норм ненашол...

ZagZag 16.12.2008 06:33

Из справочника
Цитата:

imagecopy
(PHP 4, PHP 5)

imagecopy — Copy part of an image

Description
bool imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )
Copy a part of src_im onto dst_im starting at the x,y coordinates src_x , src_y with a width of src_w and a height of src_h . The portion defined will be copied onto the x,y coordinates, dst_x and dst_y .

Parameters

dst_im
Destination image link resource.

src_im
Source image link resource.

dst_x
x-coordinate of destination point.

dst_y
y-coordinate of destination point.

src_x
x-coordinate of source point.

src_y
y-coordinate of source point.

src_w
Source width.

src_h
Source height.


Return Values
Returns TRUE on success or FALSE on failure.

Examples

Example #1 Cropping the PHP.net logo

<?php
// Create image instances
$src = imagecreatefromgif('php.gif');
$dest = imagecreatetruecolor(80, 40);

// Copy
imagecopy($dest, $src, 0, 0, 20, 13, 80, 40);

// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);

imagedestroy($dest);
imagedestroy($src);
?>
l

ZagZag 16.12.2008 06:34

Также смотри:
imagecopymerge — Copy and merge part of an image
imagecopymergegray — Copy and merge part of an image with gray scale
imagecopyresampled — Copy and resize part of an image with resampling
imagecopyresized — Copy and resize part of an image

DTW 16.12.2008 06:42

Вот как я применял

PHP код:

<?
header
("Content-type: image/gif");
$im imagecreatefromjpeg("fon.jpeg") ;
$serverip "127.0.0.1";
$port "800";
function 
status($serverip$port) {
$sockres = @fsockopen($serverip$port$errno$errstr1);
if (!
$sockres) {
return 
"off.gif";
 } else {
 @
fclose($sockres);
return 
"on.gif";
 }
}
$st2status($serverip$port);
$im2 imagecreatefromgif($st2) ;
$color imagecolorallocate($im,255,255,255) ;
$str  ="STATUS:";
imagestring($im,2,250,85,$str,$color) ;
$dX ="305";
$dY="88";
$dW="32";
$dH="8";
imagecopyresized($im,$im2,$dX,$dY,0,0,$dW,$dH,32,8) ;
imagepng($im) ;
imagedestroy($im) ;

?>


SYMBiO 16.12.2008 06:59

DTW, зачем ети сокеты?
мне просто обрезать картинку надо о_О

при компиляции (скрипта сдернутого с пхп.нет) выдает путь к пхп. что нетак хз

xcedz 16.12.2008 07:05

=\
http://i-novice.net/2-sposoba-sozdaniya-thumbnail-na-php/

$src - имя исходной картинки
$dest - имя картинки-результата,
$x, $y - координаты левого верхнего угла прямоугольника, который будет вырезан из основной картинки,
$width - ширина выделенной области,
$height - и ее высота.


PHP код:

<?  
function img_crop($src$dest$x$y$width$height$rgb 0xFFFFFF$quality 100) {  
  
    if (!
file_exists($src)) {  
        return 
false;  
    }  
  
    
$size getimagesize($src);  
  
    if (
$size === false) {  
        return 
false;  
    }  
  
    
$format strtolower(substr($size['mime'], strpos($size['mime'], '/') + 1));  
    
$icfunc 'imagecreatefrom'.$format;  
  
    if (!
function_exists($icfunc)) {  
        return 
false;  
    }  
  
    
$isrc  $icfunc($src);  
    
$idest imagecreatetruecolor($width$height);  
  
    
imagefill($idest00$rgb);  
    
imagecopyresampled($idest$isrc00$x$y$width$height$width$height);  
  
    
imagejpeg($idest$dest$quality);  
  
    
imagedestroy($isrc);  
    
imagedestroy($idest);  
  
    return 
true;  
}  
?>


SYMBiO 16.12.2008 07:36

xcedz протести плз. у меня молчит.

optimazer 16.12.2008 12:59

Цитата:

<?php
function crop_img($sp,$x,$y,$w,$h,$dst)
{
list($width,$height,$t)=getimagesize($sp);
if ($t == 1) {
$src = imagecreatefromgif($sp);
}elseif ($t == 2){
$src = imagecreatefromjpeg($sp);
}else{
$src = imagecreatefrompng($sp);
}
if ($x + $w <= $width and $y + $h <= $height) {
$tmp = imagecreatetruecolor($w,$h);
imagecopy($tmp,$src,$x,$y,0,0,$w,$h);
if ($t == 1) {
imagegif($tmp,$dst,100);
}elseif ($t == 2){
imagejpeg($tmp,$dst,100);;
}else{
imagepng($tmp,$dst,100);
}
imagedestroy($tmp);
imagedestroy($src);
return TRUE;
}else{
echo "error";
return FALSE;
}
}
?>
где $sp - изображение из которого вырезать область
$x, $y - абсцисса и ордината верхнего левого угла области которую нужно вырезать
$w, $h - ширина и высота соответственно
$dst - выходная картинка

принимает gif, jpeg, png
выходной тип изображения тот же что и входной


Время: 14:27