27. oktober 2006 - 08:02
Der er
3 kommentarer og 1 løsning
perspektivere et billede med php?
Jeg undrer mig om det er muligt at perspektivere (få billedet til at blive smallere i den ene ende) et billede med php, og hvis det er muligt om der så var nogle der kendte nogle eks. på det...?
Annonceindlæg tema
Offentlig digitalisering
Fra effektivisering til digital suverænitet. Hvordan skaber det offentlige en digital fremtid med AI, sikkerhed og kontrol i centrum?
27. oktober 2006 - 08:53
#1
Ja, det er muligt, men besværligt ;) Kender ikke lige nogen klasse der kan gøre det...
27. oktober 2006 - 09:05
#2
Hmm, kiggede lige i mit bibliotek, jeg har faktisk en, som jeg vist engang har nakket fra php.net: <?php function ImageSkew( $image, $angle, $direction = 0 ) { $is = imagecreatefromjpeg( $image ); $width = imagesx( $is ); $height = imagesy( $is ); $id = imagecreate( $width, $height ); // MATTE COLOR $bgColor = imagecolorallocate( $id, 0, 255, 0 ); imagefill( $id, 0, 0, $bgColor ); $diff = ($angle / 90); $currentHeight = $height; $currentY = 0; if ( $direction == 1 ) { $currentHeight = 0; $currentY = $height; } for ( $i = 0; $i < $width; $i++ ) { if ($pDirection == 0) { imagecopyresampled( $id, $is, $i, $currentY, $i, 0, 1, $currentHeight, 1, $height ); } else { imagecopyresampled( $id, $is, ($width - $i), $currentY, ($width - $i), 0, 1, $currentHeight, 1, $height ); } if ( $direction == 0 ) { $currentHeight = $currentHeight - ( $diff * 2 ); } else { $currentHeight = $height - ( $i * ( $diff * 2 ) ); } $currentY = ( $height - $currentHeight ) / 2; } return $id; } header("Content-Type: image/jpeg"); $im = ImageSkew( "test.jpg" ); imagejpeg( $im ); ?> Du kan ændre $bgColor til en matte der passer dig, f.eks. hvid
27. oktober 2006 - 09:09
#3
Dette er faktisk bedre: function ImageSkew( $is, $angle, $direction = 0 ) { $width = imagesx( $is ); $height = imagesy( $is ); $id = imagecreate( $width, $height ); // MATTE COLOR $bgColor = imagecolorallocate( $id, 0, 255, 0 ); imagefill( $id, 0, 0, $bgColor ); $diff = ($angle / 90); $currentHeight = $height; $currentY = 0; if ( $direction == 1 ) { $currentHeight = 0; $currentY = $height; } for ( $i = 0; $i < $width; $i++ ) { if ( $direction == 0 ) { imagecopyresampled( $id, $is, $i, $currentY, $i, 0, 1, $currentHeight, 1, $height ); } else { imagecopyresampled( $id, $is, ($width - $i), $currentY, ($width - $i), 0, 1, $currentHeight, 1, $height ); } if ( $direction == 0 ) { $currentHeight = $currentHeight - ( $diff * 2 ); } else { $currentHeight = $height - ( $i * ( $diff * 2 ) ); } $currentY = ( $height - $currentHeight ) / 2; } return $id; } header("Content-Type: image/jpeg"); $im = imagecreatefromjpeg( "test.jpg" ); $im = ImageSkew( $im, 5, 0 ); imagejpeg( $im ); Så tager den bare en image resource, i stedet for en jpeg ;)
27. oktober 2006 - 10:12
#4
jeg takker mange gange... (:
Vi tilbyder markedets bedste kurser inden for webudvikling