Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function perspective($i,$gradient=0.9,$rightdown=true,$background=0xFFFFFF) {
- $mult=3;
- $w=imagesx($i);
- $h=imagesy($i);
- $image=imagecreatetruecolor($w*$mult,$h*$mult);
- imagecopyresized($image,$i,0,0,0,0,$w*$mult,$h*$mult,$w,$h);
- imagedestroy($i);
- $w*=$mult;
- $h*=$mult;
- $im=imagecreatetruecolor($w,$h);
- $background=imagecolorallocate($im,($background>>16)&0xFF,($background>>8)&0xFF,$background&0xFF);
- imagefill($im,0,0,$background);
- imageantialias($im,true);
- $nh=$h-($h*$gradient);
- for ($x=0; $x<$w; $x++) {
- $ni=(($rightdown) ? $x : $w-$x);
- $p=intval($h-(($ni/$w)*$nh));
- if (($p%2)<>0)
- $p-=1;
- $nx=intval(($p-$h)/2);
- imagecopyresampled($im,$image,$x,0,$x,$nx,1,$p,1,$h-1);
- imageline($im,$x,$h-1,$x,$h+$nx,$background);
- imageline($im,$x,0,$x,-$nx-1,$background);
- }
- imagedestroy($image);
- imagefilter($im,IMG_FILTER_SMOOTH,10);
- $i=imagecreatetruecolor($w/$mult,$h/$mult);
- imageantialias($i,true);
- imagecopyresampled($i,$im,0,0,0,0,$w,$h,$w*$mult,$h*$mult);
- imagedestroy($im);
- return $i;
- }
- function makeTrapeziumImage($image, $gradient, $rightToLeft = false, $background = 0xFFFFFF, $supersampleScale = 3) {
- $originalWidth = imagesx($image);
- $originalHeight = imagesy($image);
- $supersampledWidth = $originalWidth * $supersampleScale;
- $supersampledHeight = $originalHeight * $supersampleScale;
- $supersampledImage = imagecreatetruecolor($supersampledWidth, $supersampledHeight);
- imagecopyresized($supersampledImage, $image,
- 0, 0, 0, 0,
- $supersampledWidth, $supersampledHeight, $originalWidth, $originalHeight);
- $workingImage = imagecreatetruecolor($supersampledWidth, $supersampledHeight);
- $backgroundColour = imagecolorallocate($workingImage, ($background >> 16) & 0xFF, ($background >> 8) & 0xFF, $background & 0xFF);
- imagefill($workingImage, 0, 0, $backgroundColour);
- imageantialias($workingImage,true);
- $endHeight = $supersampledHeight - ($supersampledHeight * $gradient);
- for ($x = 0; $x < $supersampledWidth; $x++) {
- $cX = ($rightToLeft ? $supersampledWidth - $x : $x);
- $dstHeight = $supersampledHeight - ((($cX + 1) / $supersampledWidth) * $endHeight);
- $dstY = intval(($supersampledHeight - $dstHeight) / 2) - 1; // -1 required as zero-indexed
- $dstY = ($dstY < 0 ? 0 : $dstY); // Rounding can make $dstY = -1
- $dstHeight = intval($dstHeight); // Round the height after calculating $dstY
- imagecopyresampled($workingImage, $supersampledImage,
- $cX, $dstY, $cX, 0,
- 1, $dstHeight, 1, $supersampledHeight);
- }
- imagedestroy($supersampledImage);
- imagefilter($workingImage, IMG_FILTER_SMOOTH, 10);
- $resizedImage = imagecreatetruecolor($originalWidth, $originalHeight);
- imageantialias($resizedImage, true);
- imagecopyresampled($resizedImage, $workingImage,
- 0, 0, 0, 0,
- $originalWidth, $originalHeight, $supersampledWidth, $supersampledHeight);
- imagedestroy($workingImage);
- return $resizedImage;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement