Salut est-il possible de transformer une perspective d'images ... donc sa nouvelle forme est un trapèze isocèle? je vis une solution en utilisant ImageMagick, mais cela impliquerait peut-être réécrire l'ensemble de mon script de manipulation d'images ... (sans parler de l'apprentissage, dont je suis allergique)PHP GD perspective de l'image
2
A
Répondre
4
GD ne supporte pas les manipulations d'image 3D :( La solution à l'aide ImageMagick est pas complexe: http://valokuva.org/?p=112
10
J'ai amélioré la fonction que James a posté
Ajouté:.
- perspective verticale/horizontale s upport
- transparence
- il ressemble plus à des objets en rotation maintenant 3d (plus près ojets sont plus en plus loin sont plus petits)
Voici ma fonction:
define("TOP",0);
define("BOTTOM",1);
define("LEFT",2);
define("RIGHT",3);
function perspective($i,$gradient=0.85,$rightdown=TOP,$background=0xFFFFFF, $alpha=0) {
$w=imagesx($i);
$h=imagesy($i);
$col=imagecolorallocatealpha($i,($background>>16)&0xFF,($background>>8)&0xFF,$background&0xFF,$alpha);
$mult=5;
$li=imagecreatetruecolor($w*$mult,$h*$mult);
imagealphablending($li,false);
imagefilledrectangle($li,0,0,$w*$mult,$h*$mult,$col);
imagesavealpha($li,true);
imagecopyresized($li,$i,0,0,0,0,$w*$mult,$h*$mult,$w,$h);
imagedestroy($i);
$w*=$mult;
$h*=$mult;
$image=imagecreatetruecolor($w,$h);
imagealphablending($image,false);
imagefilledrectangle($image,0,0,$w,$h,$col);
imagealphablending($image,true);
imageantialias($image,true);
$test=$h*$gradient;
$rdmod=$rightdown%2;
$min=1;
if($rightdown<2){
for($y=0;$y<$h;$y++){
$ny=$rdmod? $y : $h-$y;
$off=round((1-$gradient)*$w*($ny/$h));
$t=((1-pow(1-pow(($ny/$h),2),0.5))*(1-$gradient)+($ny/$h)*$gradient);
$nt=$rdmod? $t : 1-$t;
if(abs(0.5-$nt)<$min){
$min=abs(0.5-$nt);
$naty=$off;
}
imagecopyresampled($image,$li,
round($off/2),$y,
0,abs($nt*$h),
$w-$off,1,
$w,1);
}
} else {
for($x=0;$x<$w;$x++){
$nx=$rdmod? $x : $w-$x;
$off=round((1-$gradient)*$h*($nx/$w));
$t=((1-pow(1-pow(($nx/$w),2),0.5))*(1-$gradient)+($nx/$w)*$gradient);
$nt=$rdmod? $t : 1-$t;
if(abs(0.5-$nt)<$min){
$min=abs(0.5-$nt);
$natx=$off;
}
imagecopyresampled($image,$li,
$x,round($off/2),
abs($nt*$w),0,
1,$h-$off,
1,$h);
}
}
imagedestroy($li);
imageantialias($image,false);
imagealphablending($image,false);
imagesavealpha($image,true);
$i=imagecreatetruecolor(($w+$naty)/$mult,($h+$natx)/$mult);
imagealphablending($i,false);
imagefilledrectangle($i,0,0,($w+$naty)/$mult,($h+$natx)/$mult,$col);
imagealphablending($i,true);
imageantialias($i,true);
imagecopyresampled($i,$image,0,0,0,0,($w+$naty)/$mult,($h+$natx)/$mult,$w,$h);
imagedestroy($image);
imagealphablending($i,false);
imageantialias($i,false);
imagesavealpha($i,true);
return $i;
}
Exemples:
Original image: http://imgur.com/iX5Aski
Utilisation de la fonction:
$img=perspective($img,0.5,TOP,0xFFFFFF,127);
Résultat:
$img=perspective($img,0.2,RIGHT,0xFFFFFF,127);
Résultat:
+0
C'est IMPRESSIONNANT, merci @Daniel –
Questions connexes
- 1. Php Gd rotate image
- 2. PHP/GD ImageSaveAlpha et ImageAlphaBlending
- 3. PHP/GD Gaussian Blur Effet
- 4. PHP GD-imagejpeg incapable d'ouvrir
- 5. PHP GD donne une erreur
- 6. Réflexion d'image translucide en PHP GD
- 7. php et true type collection en gd
- 8. Embedding IPTC données d'image avec PHP GD
- 9. PHP/GD - Redéfinition d'images et Recadrage
- 10. fusion d'images en utilisant php dans GD
- 11. compilez PHP GD-sur Mac OSX 10.5
- 12. Superposition de couleur sur un JPEG avec PHP/GD?
- 13. Mauvaise qualité de l'image GIF en PHP GD
- 14. PHP GD, imagecreatefromstring(); comment obtenir les dimensions de l'image?
- 15. projection en perspective inverse
- 16. JavaScript Background Perspective Library
- 17. PHP/GD, comment copier un cercle d'une image à l'autre?
- 18. Colorisation et permutation des couleurs avec PHP GD Image Library?
- 19. PHP GD: Comment obtenir imagedata en tant que chaîne binaire?
- 20. GD obtient l'image de la chaîne binaire
- 21. Chargement des images dans GD
- 22. Bogue générateur d'image GD
- 23. php gd: quand je rogner des images par php quelques images sortent smushed
- 24. Sortie de l'image avec du texte souligné à l'aide de la bibliothèque GD GD
- 25. Projection en perspective - Aidez un Noob
- 26. Comment ajouter une perspective à un UIImageView
- 27. Comment peindre un bitmap avec perspective?
- 28. wpf interface semblable à une perspective
- 29. perl GD dessiner une forme
- 30. Création d'une extension de perspective indépendante de la version
lien mort, mais voici le plus récent cache: https://web.archive.org/ web/20130424232913/http: //valokuva.org/? p = 112 –