Comment manipuler une image ? (deplacement + rotation)

Résolu
franco_se Messages postés 151 Date d'inscription samedi 1 novembre 2003 Statut Membre Dernière intervention 30 juillet 2018 - 19 déc. 2006 à 00:09
alcoveforlove Messages postés 12 Date d'inscription mercredi 8 décembre 2004 Statut Membre Dernière intervention 18 novembre 2011 - 18 nov. 2011 à 18:53
bonjours


je voudrais savoir comment faire pour manipuler une image, a savoir la
deplacer, et lui appliquer une rotation. Mon but étant en fait de
deplacer des images sur un fond blanc, puis de les fusionner pour
generer une image unique.


apres une rapide recherche, je n'ai rien trouver de tel .............


quelqu'un aurait une idée, ou une piste pour un tel script?


merci

8 réponses

Arto_8000 Messages postés 1044 Date d'inscription lundi 7 mars 2005 Statut Membre Dernière intervention 13 juillet 2010 7
19 déc. 2006 à 03:30
Pour faire des rotations à ma connaissance c'est impossible. Sinon pour les déplacements il suffit que ton image soit en position absolue pour pouvoir la déplacer comme bon te semble dans l'écran.



Ensuite pour la déplacer il suffit d'utiliser les propriétés left et top css.

function moveImgTo(id,x,y)
{
document.getElementById(id).style.left = x;
document.getElementById(id).style.top = y;
}
3
franco_se Messages postés 151 Date d'inscription samedi 1 novembre 2003 Statut Membre Dernière intervention 30 juillet 2018 2
19 déc. 2006 à 11:16
merci arto

par ailleurs, j'ai reussi a trouver une fojnction qui permette la rotaion d'une image:
http://www.walterzorn.com/rotate_img/rotate_img.htm

maintenant, il ne me reste plus qu'a :
1/ comprendre comment ça marche ( je debute en javascript )
2/ modifier tout ça pour que la rotation se fasse a la souris ( on clique sur un coin de l'image, et en bougeant la souris, ça la fait tourner ............... )

un jeu d'enfant ......................................................................
0
Arto_8000 Messages postés 1044 Date d'inscription lundi 7 mars 2005 Statut Membre Dernière intervention 13 juillet 2010 7
21 déc. 2006 à 03:22
Le principle qu'il utilise est pas très compliqué ... Il découpe l'image avec des divs pour que chaque div contienne un pixel de l'image et ensuite il déplace les divs pour donner l'effet que l'image a subit une rotation.
0
PetoleTeam Messages postés 3426 Date d'inscription lundi 26 décembre 2005 Statut Membre Dernière intervention 14 janvier 2011 17
21 déc. 2006 à 20:38
B
onjour...
comme le dis Arto_8000 rien de complexe c'est la même approche que j'ai faite sur


[code.aspx?ID=38317 EFFET
D'EXPLOSION SUR TEXTE ET/OU IMAGE], les possibilités semble infinie si ce n'est la gourmandise en ressource

...
;0)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
alcoveforlove Messages postés 12 Date d'inscription mercredi 8 décembre 2004 Statut Membre Dernière intervention 18 novembre 2011 1
18 nov. 2011 à 12:49
<?xml version="1.0" encoding="utf-8"?>
<html>

<head>

<style type="text/css">
body {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
background-color : #fff;
}

</style>

</head>






<script type="text/javascript">



var oh = document.body.offsetHeight; // taille de l'écran
var ow = document.body.offsetWidth;
var svgNS = "http://www.w3.org/2000/svg";


svg = document.createElementNS(svgNS,"svg"); // créer une zone svg
document.body.appendChild(svg); // l'insérer dans le body

var idobj = 0; // compteur d'objet rondOBJ ne sert pas à grand-chose ici


function rondOBJ()
{
that = this;
this.o = document.createElementNS(svgNS,"image"); // créer une image svg
this.x = ow/2.5; // positionner à peu près au milieu de l'écran
this.y = oh/2.5;
this.angle = 90; // définir l'angle de départ

this.o.setAttribute("x",this.x); // positionner l'image en x
this.o.setAttribute("y",this.y); // positionner l'image en y
this.o.setAttribute("width","100"); // taille de l'image en largeur
this.o.setAttribute("height","200"); // taille de l'image en hauteur
this.o.setAttributeNS("http://www.w3.org/1999/xlink","href","2347.gif"); // xlink:href path de l'image

this.o.setAttribute("transform","rotate("+that.angle+","+(this.x+50)+","+(this.y+100)+")"); // appliquer la rotation


svg.appendChild(this.o); // afficher le tout
idobj++;



}


function keyCheck(e) {
if(that.angle==360) { that.angle = 0; }
if(e.keyCode == 37) { that.angle=that.angle+10; } // changer d'angle en fonction des touches flèches
if(e.keyCode == 39) { that.angle=that.angle-10; }
if(e.keyCode == 38) {
if(that.angle<180) // avancer
{
that.x = that.x + 1;
that.y = that.y + 1;
}

if(that.angle>180) // reculer
{
that.x = that.x - 1;
that.y = that.y - 1;
}
}
// afficher le tout
that.o.setAttribute("transform","rotate("+that.angle+","+(that.x+50)+","+(that.y+100)+")");


}




var rd = new rondOBJ();

document.onkeydown = keyCheck;








</script>




</html>
0
alcoveforlove Messages postés 12 Date d'inscription mercredi 8 décembre 2004 Statut Membre Dernière intervention 18 novembre 2011 1
18 nov. 2011 à 12:59
il y a un défaut sur le déplacement en x et en y SI quelqu'un trouve la solution je suis preneur
0
alcoveforlove Messages postés 12 Date d'inscription mercredi 8 décembre 2004 Statut Membre Dernière intervention 18 novembre 2011 1
18 nov. 2011 à 17:26
révision du code pourri produit ce matin lol....

<?xml version="1.0" encoding="utf-8"?>
<html>

<head>

<style type="text/css">
body {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
background-color : #fff;
}

</style>

</head>






<script type="text/javascript">

var oh = document.body.offsetHeight; // taille de l'écran
var ow = document.body.offsetWidth;
var svgNS = "http://www.w3.org/2000/svg";


svg = document.createElementNS(svgNS,"svg"); // créer une zone svg
document.body.appendChild(svg); // l'insérer dans le body

var idobj = 0; // compteur d'objet rondOBJ ne sert pas à grand-chose ici


function rondOBJ()
{
that = this;
this.o = document.createElementNS(svgNS,"image"); // créer une image svg
this.x = ow/2.5; // positionner à peu près au milieu de l'écran
this.y = oh/2.5;
this.angle = 90; // définir l'angle de départ

this.o.setAttribute("x",this.x); // positionner l'image en x
this.o.setAttribute("y",this.y); // positionner l'image en y
this.o.setAttribute("width","100"); // taille de l'image en largeur
this.o.setAttribute("height","200"); // taille de l'image en hauteur
this.o.setAttributeNS("http://www.w3.org/1999/xlink","href","2347.gif"); // xlink:href path de l'image

this.o.setAttribute("transform","rotate("+that.angle+","+(this.x+50)+","+(this.y+100)+")"); // appliquer la rotation

// petit témoin
document.title = "angle:"+that.angle+" | x="+that.x+" | y="+that.y;
svg.appendChild(this.o); // afficher le tout
idobj++;



}


function keyCheck(e) {

if(that.angle==0) { that.angle = 360; }
if(that.angle==370) { that.angle = 10; }

if(e.keyCode == 37) { that.angle=that.angle-10; } // changer d'angle en fonction des touches flèches
if(e.keyCode == 39) { that.angle=that.angle+10; }
if(e.keyCode == 38) {
if(that.angle<180) // avancer
{
that.x = that.x + 2;
if(that.angle<90) { that.y = that.y - 2; }
if(that.angle>90) { that.y = that.y + 2; }
that.o.setAttribute("x",that.x);
that.o.setAttribute("y",that.y);
}

if(that.angle>180)
{
that.x = that.x -2;
if(that.angle<270) { that.y = that.y + 2; }
if(that.angle>270) { that.y = that.y - 2; }
that.o.setAttribute("x",that.x);
that.o.setAttribute("y",that.y);
}

}
//
that.o.setAttribute("transform","rotate("+that.angle+","+(that.x+50)+","+(that.y+100)+")");
document.title = "angle:"+that.angle+" | x="+that.x+" | y="+that.y;
}

var rd = new rondOBJ();

document.onkeydown = keyCheck;


</script>




</html>
0
alcoveforlove Messages postés 12 Date d'inscription mercredi 8 décembre 2004 Statut Membre Dernière intervention 18 novembre 2011 1
18 nov. 2011 à 18:53
CODE DEFINTIF (désolé pour le tatonnement)
ce code fait intervenir SVG nécessaire notamment pour la rotation...
SVG est compatible avec firefox pas encore avec IE à ce jour...
D'autres solutions pour déplacer et exécuter des rotations sont CSS3,
canvas, vml...

<?xml version="1.0" encoding="utf-8"?>
<html>

<head>

<style type="text/css">
body {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
background-color : #fff;
}

</style>

</head>




<script type="text/javascript">

var oh = document.body.offsetHeight; // taille de l'écran
var ow = document.body.offsetWidth;
var svgNS = "http://www.w3.org/2000/svg";


svg = document.createElementNS(svgNS,"svg"); // créer une zone svg
document.body.appendChild(svg); // l'insérer dans le body

var idobj = 0; // compteur d'objet rondOBJ ne sert pas à grand-chose ici


function rondOBJ()
{
that = this;
this.o = document.createElementNS(svgNS,"image"); // créer une image svg
this.x = ow/2.5; // positionner à peu près au milieu de l'écran
this.y = oh/2.5;
this.angle = 90; // définir l'angle de départ

this.o.setAttribute("x",this.x); // positionner l'image en x
this.o.setAttribute("y",this.y); // positionner l'image en y
this.o.setAttribute("width","150"); // taille de l'image en largeur
this.o.setAttribute("height","90"); // taille de l'image en hauteur
this.o.setAttributeNS("http://www.w3.org/1999/xlink","href","avion.gif"); // xlink:href path de l'image

this.o.setAttribute("transform","rotate("+that.angle+","+(this.x+75)+","+(this.y+45)+")"); // appliquer la rotation

// petit témoin
document.title = "angle:"+that.angle+" | x="+that.x+" | y="+that.y;
svg.appendChild(this.o); // afficher le tout
idobj++;



}


function keyCheck(e) {

if(that.angle==0) { that.angle = 360; }
if(that.angle==370) { that.angle = 10; }

if(e.keyCode == 37) { that.angle=that.angle-10; } // changer d'angle en fonction des touches flèches
if(e.keyCode == 39) { that.angle=that.angle+10; }
if(e.keyCode == 38) {
if(that.angle!=360&&that.angle!=0&&that.angle!=180)
{
if(that.angle<180)
{
that.x = that.x + 2;
if(that.angle<90&&that.angle!=0) { that.y = that.y - 2; }
if(that.angle>90&&that.angle!=360) { that.y = that.y + 2; }
}
else
{
that.x = that.x -2;
if(that.angle<270) { that.y = that.y + 2; }
if(that.angle>270) { that.y = that.y - 2; }
}
}
else
{
if(that.angle==360||that.angle==0) { that.y = that.y - 2; }
if(that.angle==180) { that.y = that.y + 2; }
}

that.o.setAttribute("x",that.x);
that.o.setAttribute("y",that.y);
}
//
that.o.setAttribute("transform","rotate("+that.angle+","+(that.x+75)+","+(that.y+45)+")");
document.title = "angle:"+that.angle+" | x="+that.x+" | y="+that.y;
}

var rd = new rondOBJ();

document.onkeydown = keyCheck;


</script>




</html>
0
Rejoignez-nous