imageClipCorners routine in the 'Code Snippets' section

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
DarkConsultant
Forum Newbie
Posts: 17
Joined: Mon Apr 14, 2008 3:17 am
Location: Luton, England

imageClipCorners routine in the 'Code Snippets' section

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: imageClipCorners routine in the 'Code Snippets' section

Post 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?
User avatar
DarkConsultant
Forum Newbie
Posts: 17
Joined: Mon Apr 14, 2008 3:17 am
Location: Luton, England

Re: imageClipCorners routine in the 'Code Snippets' section

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: imageClipCorners routine in the 'Code Snippets' section

Post 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.
User avatar
DarkConsultant
Forum Newbie
Posts: 17
Joined: Mon Apr 14, 2008 3:17 am
Location: Luton, England

Re: imageClipCorners routine in the 'Code Snippets' section

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: imageClipCorners routine in the 'Code Snippets' section

Post 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.
User avatar
DarkConsultant
Forum Newbie
Posts: 17
Joined: Mon Apr 14, 2008 3:17 am
Location: Luton, England

Re: imageClipCorners routine in the 'Code Snippets' section

Post 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.
User avatar
DarkConsultant
Forum Newbie
Posts: 17
Joined: Mon Apr 14, 2008 3:17 am
Location: Luton, England

Re: imageClipCorners routine in the 'Code Snippets' section

Post by DarkConsultant »

Addendum ...

After 5 minutes and several refreshes I now get a blank screen and no code.
User avatar
DarkConsultant
Forum Newbie
Posts: 17
Joined: Mon Apr 14, 2008 3:17 am
Location: Luton, England

Re: imageClipCorners routine in the 'Code Snippets' section

Post 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?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: imageClipCorners routine in the 'Code Snippets' section

Post by onion2k »

Does GD appear in php_info() now?
User avatar
DarkConsultant
Forum Newbie
Posts: 17
Joined: Mon Apr 14, 2008 3:17 am
Location: Luton, England

Re: imageClipCorners routine in the 'Code Snippets' section

Post 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 ...
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: imageClipCorners routine in the 'Code Snippets' section

Post by onion2k »

Did you remove the header("Content-type: image/jpeg"); line?
User avatar
DarkConsultant
Forum Newbie
Posts: 17
Joined: Mon Apr 14, 2008 3:17 am
Location: Luton, England

Re: imageClipCorners routine in the 'Code Snippets' section

Post by DarkConsultant »

Hi,

It made no differnece either way.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: imageClipCorners routine in the 'Code Snippets' section

Post 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.
User avatar
DarkConsultant
Forum Newbie
Posts: 17
Joined: Mon Apr 14, 2008 3:17 am
Location: Luton, England

Re: imageClipCorners routine in the 'Code Snippets' section

Post 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.
Post Reply