Page 1 of 1

imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 4:49 am
by DarkConsultant
Hello Everyone,

I have a question regarding the imageClipCorners routine in the 'Code Snippets' section.

I cannot work out how to use this function could someone please show me.

I am new to php and still have a lot to learn.

Thanx in anticipation

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 5:06 am
by onion2k
The usage is at the top of the script..

Code: Select all

$i = imagecreatefromjpeg("xxx.jpg");
$i = imageClipCorners($i);
 
header("Content-type: image/jpeg");
imagejpeg($i);
What are you having difficulty with?

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 5:22 am
by DarkConsultant
Hi,

I must be missing something basic. I have editted the picture source to an image on my PC but all I can display is random letters and numbers.

Please go gentle with me I am new to PHP, old and have cataracts in my right eye.

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 5:24 am
by onion2k
That's odd. Could you post your script here please. Use code tags ... so you need to post [syntax=php]your code[/syntax] ... cheers.

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 6:26 am
by DarkConsultant
Hi,

Code: Select all

 
<? php
 
$i = imagecreatefromjpeg("test.jpg"); 
$i = imageClipCorners($i); 
 
header("Content-type: image/jpeg"); 
imagejpeg($i); 
 
 
 
//Corner rounding function. 
 
function imageClipCorners($i,$xrad=20,$yrad=20,$r=255,$g=255,$b=255) { 
 
$i_x = imagesx($i); $i_y = imagesy($i); 
 
$gdCornerSource = imagecreatefromstring(base64_decode(cornerpng())); 
$gdCorner_x = imagesx($gdCornerSource); 
$gdCorner_y = imagesy($gdCornerSource); 
 
$gdCorner1 = imagecreatefromstring(base64_decode(blankpng())); 
$gdCorner2 = imagecreatefromstring(base64_decode(blankpng())); 
$gdCorner3 = imagecreatefromstring(base64_decode(blankpng())); 
$gdCorner4 = imagecreatefromstring(base64_decode(blankpng())); 
 
for ($y=0;$y<imagesy($gdCornerSource);$y++) { 
for ($x=0;$x<imagesx($gdCornerSource);$x++) { 
$rgb = imagecolorat($gdCornerSource,$x,$y); 
$a = ($rgb >> 24) & 0xFF; 
$colour = imagecolorallocatealpha($gdCorner1,$r,$g,$b,$a); 
imagesetpixel($gdCorner1,$x,$y,$colour); 
$colour = imagecolorallocatealpha($gdCorner2,$r,$g,$b,$a); 
imagesetpixel($gdCorner2,$gdCorner_x-$x,$y,$colour); 
$colour = imagecolorallocatealpha($gdCorner3,$r,$g,$b,$a); 
imagesetpixel($gdCorner3,$gdCorner_x-$x,$gdCorner_y-$y,$colour); 
$colour = imagecolorallocatealpha($gdCorner4,$r,$g,$b,$a); 
imagesetpixel($gdCorner4,$x,$gdCorner_y-$y,$colour); 
 
} 
} 
 
imagecopyresampled($i,$gdCorner1,0,0,0,0,$xrad,$yrad,$gdCorner_x,$gdCorner_y); 
imagecopyresampled($i,$gdCorner2,$i_x-$xrad,0,0,0,$xrad,$yrad,$gdCorner_x,$gdCorner_y); 
imagecopyresampled($i,$gdCorner3,$i_x-$xrad,$i_y-$yrad,0,0,$xrad,$yrad,$gdCorner_x,$gdCorner_y); 
imagecopyresampled($i,$gdCorner4,0,$i_y-$yrad,0,0,$xrad,$yrad,$gdCorner_x,$gdCorner_y); 
 
return $i; 
 
} 
 
//Base64 encoded corner PNG image 
 
function cornerpng() { 
 
$c = "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29m"; 
$c .= "dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAIBSURBVHjaYmRgYPjPMHDgOhTfAuJ7QPwYiJ8D8Rsg"; 
$c .= "/gjE3wECiIXODnoIxEeB+AQQnwLic/////+NTwNAANHDgaCQ2AnEu4B4L9BBD0jRDBBAtHTgHSDeAMSb"; 
$c .= "gI46TK4hAAFECwfeB+IVQLwK6LALlBoGEEAM0ExCDfwdiGcAsRXQYQzUwgABRC0HHgTiGGo6DIYBAohS"; 
$c .= "B/4D4slArEkLx4EwQABR4kBQWsunlcNgGCCAyHXgSSAOobXjQBgggMhx4G4gdqSH40AYIIBIdeB2ILag"; 
$c .= "l+NAGCCAGEgMObo6DoQBAoiBhDTnSG/HgTBAADEQmVtDBsJxIAwQQExE1DITgArXDFR7DCCACIXg5IEK"; 
$c .= "ORgGCCB8IXgIiKcxDDAACCBcDvwBxLOBPrg+0A4ECCBcDlwIdNwShkEAAAKICUd7bhHDIAEAAYTNgSuA"; 
$c .= "oXdssDgQIICYsDTTVzEMIgAQQOgO3ECtZjq1AEAAMaH1vjYxDDIAEEDIDtxJSe+LVgAggJAduIthEAKA"; 
$c .= "AGJC6vHvHYwOBAggmAOPktrjpxcACCCYA08wDFIAEEAwB54arA4ECCAm6PDXucHqQIAAAjuQ0BDYQAKA"; 
$c .= "AGKCDh4OWgAQQEzQkc1BCwACiAk67DpoAUAAMUHHhActAAggJuiA9aAFAAHEBG3FDFoAEEBM0JHRQQsA"; 
$c .= "AgwAlTI79UaGSUQAAAAASUVORK5CYII="; 
 
return $c; 
 
} 
 
//Base64 encoded 127 alpha PNG image 
 
function blankpng() { 
 
$c = "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29m"; 
$c .= "dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADqSURBVHjaYvz//z/DYAYAAcTEMMgBQAANegcCBNCg"; 
$c .= "dyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAAN"; 
$c .= "egcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQ"; 
$c .= "oHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAA"; 
$c .= "DXoHAgTQoHcgQAANegcCBNCgdyBAgAEAMpcDTTQWJVEAAAAASUVORK5CYII="; 
 
return $c; 
 
} 
 
?>
 
Like I said this is 'as is' except for the file name which is in the same folder as the php function.

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 6:31 am
by onion2k
Right... there's two problems..

1. Delete line 1.

2. On line 2 - "<? php" ... delete the space. "<?php" should be the very first thing that appears in the script. Nothing should appear before it.

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 6:57 am
by DarkConsultant
Hi,

Made no difference ... just got

> 24) & 0xFF; $colour = imagecolorallocatealpha($gdCorner1,$r,$g,$b,$a); imagesetpixel($gdCorner1,$x,$y,$colour); $colour = imagecolorallocatealpha($gdCorner2,$r,$g,$b,$a); imagesetpixel($gdCorner2,$gdCorner_x-$x,$y,$colour); $colour = imagecolorallocatealpha($gdCorner3,$r,$g,$b,$a); imagesetpixel($gdCorner3,$gdCorner_x-$x,$gdCorner_y-$y,$colour); $colour = imagecolorallocatealpha($gdCorner4,$r,$g,$b,$a); imagesetpixel($gdCorner4,$x,$gdCorner_y-$y,$colour); } } imagecopyresampled($i,$gdCorner1,0,0,0,0,$xrad,$yrad,$gdCorner_x,$gdCorner_y); imagecopyresampled($i,$gdCorner2,$i_x-$xrad,0,0,0,$xrad,$yrad,$gdCorner_x,$gdCorner_y); imagecopyresampled($i,$gdCorner3,$i_x-$xrad,$i_y-$yrad,0,0,$xrad,$yrad,$gdCorner_x,$gdCorner_y); imagecopyresampled($i,$gdCorner4,0,$i_y-$yrad,0,0,$xrad,$yrad,$gdCorner_x,$gdCorner_y); return $i; } //Base64 encoded corner PNG image function cornerpng() { $c = "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29m"; $c .= "dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAIBSURBVHjaYmRgYPjPMHDgOhTfAuJ7QPwYiJ8D8Rsg"; $c .= "/gjE3wECiIXODnoIxEeB+AQQnwLic/////+NTwNAANHDgaCQ2AnEu4B4L9BBD0jRDBBAtHTgHSDeAMSb"; $c .= "gI46TK4hAAFECwfeB+IVQLwK6LALlBoGEEAM0ExCDfwdiGcAsRXQYQzUwgABRC0HHgTiGGo6DIYBAohS"; $c .= "B/4D4slArEkLx4EwQABR4kBQWsunlcNgGCCAyHXgSSAOobXjQBgggMhx4G4gdqSH40AYIIBIdeB2ILag"; $c .= "l+NAGCCAGEgMObo6DoQBAoiBhDTnSG/HgTBAADEQmVtDBsJxIAwQQExE1DITgArXDFR7DCCACIXg5IEK"; $c .= "ORgGCCB8IXgIiKcxDDAACCBcDvwBxLOBPrg+0A4ECCBcDlwIdNwShkEAAAKICUd7bhHDIAEAAYTNgSuA"; $c .= "oXdssDgQIICYsDTTVzEMIgAQQOgO3ECtZjq1AEAAMaH1vjYxDDIAEEDIDtxJSe+LVgAggJAduIthEAKA"; $c .= "AGJC6vHvHYwOBAggmAOPktrjpxcACCCYA08wDFIAEEAwB54arA4ECCAm6PDXucHqQIAAAjuQ0BDYQAKA"; $c .= "AGKCDh4OWgAQQEzQkc1BCwACiAk67DpoAUAAMUHHhActAAggJuiA9aAFAAHEBG3FDFoAEEBM0JHRQQsA"; $c .= "AgwAlTI79UaGSUQAAAAASUVORK5CYII="; return $c; } //Base64 encoded 127 alpha PNG image function blankpng() { $c = "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29m"; $c .= "dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADqSURBVHjaYvz//z/DYAYAAcTEMMgBQAANegcCBNCg"; $c .= "dyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAAN"; $c .= "egcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQ"; $c .= "oHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAA"; $c .= "DXoHAgTQoHcgQAANegcCBNCgdyBAgAEAMpcDTTQWJVEAAAAASUVORK5CYII="; return $c; } ?>

Sorry.

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 7:15 am
by DarkConsultant
Addendum ...

After 5 minutes and several refreshes I now get a blank screen and no code.

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 8:17 am
by DarkConsultant
Hello Everyone,

It seems my gd is not working, when I run phpinfo() I get no gd section although I installed 5.2.2 which should contain gd. I have modified the php.ini files extensions folder and php_gd2.dll extension and restarted the server ... no difference. gd is still not running... any ideas?

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 8:20 am
by onion2k
Does GD appear in php_info() now?

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 10:02 am
by DarkConsultant
Hello again,

I have now got my gd showing on phpinfo (there were several dll's missing, replaced all OK) and have a different result ...

ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC $.' ",#(7),01444'9=82<.342ÿÛC 2!!22222222222222222222222222222222222222222222222222ÿÀX "ÿÄ ÿĵ}!1AQa"q2‘¡#B±ÁRÑð$3br‚ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵw!1AQaq"2B‘¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’ Truncated ....

Any thoughts ...

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 10:05 am
by onion2k
Did you remove the header("Content-type: image/jpeg"); line?

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 11:27 am
by DarkConsultant
Hi,

It made no differnece either way.

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 11:36 am
by onion2k
ÿØÿà at the start of the output looks like a jpg with the wrong content type to me. Try commenting out the header() and the imagejpeg() lines and see if there's any errors. If that isn't it then I'm a bit stumped.

Re: imageClipCorners routine in the 'Code Snippets' section

Posted: Mon Apr 14, 2008 11:46 am
by DarkConsultant
Hiya,

As expected got a blank page, checking source revealed perfect empty page.

The last time I got a problem with php I uninstalled and reinstalled it, I'll give that a try.

You should get a medal for your patience mate and I thank you so much for all the effort you have put into my problem.