[PHP] GD Copying Images

2001-10-26 Thread Alberto

I have 2 images, and I want to copy/reescale a block from image A to image
B, when I do it (imagecopyresized) I get a gray square on image B, I think
that the problem is palette colors, how can I copy palette from image A to
image B?



Thnx



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] GD Copying Images

2001-10-26 Thread Kodrik

On Friday 26 October 2001 05:03 am, you wrote:
 I have 2 images, and I want to copy/reescale a block from image A to image
 B, when I do it (imagecopyresized) I get a gray square on image B, I think
 that the problem is palette colors, how can I copy palette from image A to
 image B?



 Thnx

GD sucks when it comes to image resizing.
You can add some code to it prior to compiling to make it better or write a 
complex php function for it.

Or, if you can install ImageMagick on your box and resize your imag through a 
exec() call.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] GD Copying Images

2001-10-26 Thread Alberto

Where can I get that code for PHP 4.0.6?

I added to ./ext/gd/gd.c

/* {{{ proto int imagecopyresizedbicubic(int dst_im, int src_im, int dst_x,
int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int
src_h)
Copy and resize part of an image */
PHP_FUNCTION(imagecopyresizedbicubic)
{
zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY, **DW, **DH;
gdImagePtr im_dst, im_src;
int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX;
int i, j;
int r, g, b, c1,c2,c3,c4,color;
float sX, sY;
float scaleX,scaleY,scaleX2,scaleY2;
GDLS_FETCH();

if (ZEND_NUM_ARGS() != 10 ||
zend_get_parameters_ex(10, DIM, SIM, DX, DY, SX,
SY, DW, DH, SW, SH) == FAILURE)
{
WRONG_PARAM_COUNT;
}

ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, DIM, -1, Image,
le_gd);
ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, Image,
le_gd);

convert_to_long_ex(SX);
convert_to_long_ex(SY);
convert_to_long_ex(SW);
convert_to_long_ex(SH);
convert_to_long_ex(DX);
convert_to_long_ex(DY);
convert_to_long_ex(DW);
convert_to_long_ex(DH);

srcX = Z_LVAL_PP(SX);
srcY = Z_LVAL_PP(SY);
srcH = Z_LVAL_PP(SH);
srcW = Z_LVAL_PP(SW);
dstX = Z_LVAL_PP(DX);
dstY = Z_LVAL_PP(DY);
dstH = Z_LVAL_PP(DH);
dstW = Z_LVAL_PP(DW);

// kopiera paletten

for( i=0; i256; i++ ) {
gdImageColorAllocate( im_dst, im_src-red[i], im_src-green[i],
im_src-blue[i] );
};

// gdImageCopyResized(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH,
srcW, srcH);

scaleX = (float)(srcW-1) / (float)dstW;
scaleY = (float)(srcH-1) / (float)dstH;

scaleX2 = scaleX/2.0f;
scaleY2 = scaleY/2.0f;

for( j=0; jdstH; j++ ) {
for( i=0; idstW; i++ ) {

sX = (float)i * scaleX;
sY = (float)j * scaleY;

c1 = gdImageGetPixel(im_src, (int)(sX), (int)(sY+scaleY2) );
c2 = gdImageGetPixel(im_src, (int)(sX), (int)(sY) );
c3 = gdImageGetPixel(im_src, (int)(sX+scaleX2), (int)(sY+scaleY2) );
c4 = gdImageGetPixel(im_src, (int)(sX+scaleX2), (int)(sY) );

r = (im_src-red[c1] + im_src-red[c2] + im_src-red[c3] +
im_src-red[c4]) / 4;
g = (im_src-green[c1] + im_src-green[c2] + im_src-green[c3]
+ im_src-green[c4]) / 4;
b = (im_src-blue[c1] + im_src-blue[c2] + im_src-blue[c3] +
im_src-blue[c4]) / 4;

color=gdImageColorClosest(im_dst,r,g,b);
gdImageSetPixel( im_dst, (i+dstX),(j+dstY), color );

};
};

RETURN_TRUE;
}


Then make; make install; and apachectl restart and I get non-defined
function when I call ImageCopyRisedBicubic, any ideas?

I prefer not to call a exec() to resize those images, if I can do it from GD
directly.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]