Gerold: Bildbreite

Hallo!

Ich lese mit img.width die Bildbreite aus und stelle bei manchen Bildern im Format .jpg und .gif fest, dass ich als Wert 0 zurückbekomme obwohl die Breite des Bildes nicht 0 ist. Bei anderen Bildern stimmt der zurückgelieferte Wert.
Wer kennt das Problem und kann mir dabei helfen.
Vielen Dank

Gerold

  1. Hallo Gerold.

    Ich lese mit img.width die Bildbreite aus und stelle bei manchen Bildern im Format .jpg und .gif fest, dass ich als Wert 0 zurückbekomme obwohl die Breite des Bildes nicht 0 ist. Bei anderen Bildern stimmt der zurückgelieferte Wert.

    Greifst du stets zur selben Zeit auf die Grafiken zu, sprich, wenn das Dokument fertig geladen wurde?

    Einen schönen Freitag noch.

    Gruß, Ashura

    --
    sh:( fo:} ch:? rl:( br: n4:~ ie:{ mo:| va:) de:> zu:} fl:( ss:) ls:[ js:|
    „It is required that HTML be a common language between all platforms. This implies no device-specific markup, or anything which requires control over fonts or colors, for example. This is in keeping with the SGML ideal.“
    [HTML Design Constraints: Logical Markup]
    1. Hallo Ashura!

      Vielen Dank für den Hinweis. Das Problem dürfte gelöst sein.

      LG
      Gerold

    2. Hallo Ashura,

      melde mich noch einmal da ich mein Problem nicht lösen konnte. Ich will die Breite des Bildes vor dem Upload auslesen. Wie kann ich erreichen, dass ich auf das Bild zugreife sobald es fertig geladen ist und nicht früher?
      Vielen Dank
      LG Gerold

      1. Hallo Gerold.

        Wie kann ich erreichen, dass ich auf das Bild zugreife sobald es fertig geladen ist und nicht früher?

        Die gebräuchliche Methode erwähnt Stefan in seinem Posting, molily postete eine Alternative.

        Einen schönen Samstag noch.

        Gruß, Ashura

        --
        sh:( fo:} ch:? rl:( br: n4:~ ie:{ mo:| va:) de:> zu:} fl:( ss:) ls:[ js:|
        „It is required that HTML be a common language between all platforms. This implies no device-specific markup, or anything which requires control over fonts or colors, for example. This is in keeping with the SGML ideal.“
        [HTML Design Constraints: Logical Markup]
        1. Hallo Ashura,

          Vielen Dank für die Antwort,

          auch mit "document.getElementById("beispiel").onload = function ()..." funktioniert es nicht.

          LG
          Gerold

          1. Hallo Gerold.

            auch mit "document.getElementById("beispiel").onload = function ()..." funktioniert es nicht.

            Zu dieser Erkenntnis ist Stefan auch gekommen. Lies ruhig den gesamtem Thread und insbesondere molilys Antwort.

            Einen schönen Samstag noch.

            Gruß, Ashura

            --
            sh:( fo:} ch:? rl:( br: n4:~ ie:{ mo:| va:) de:> zu:} fl:( ss:) ls:[ js:|
            „It is required that HTML be a common language between all platforms. This implies no device-specific markup, or anything which requires control over fonts or colors, for example. This is in keeping with the SGML ideal.“
            [HTML Design Constraints: Logical Markup]
            1. Hallo Ashura,

              ich habe den Text überflogen und bin mir nicht sicher ob ich auf mein Problem darin eine Antwort finde. Ich will ja nicht die Breite eines Bildes in einem Img-Tag auslesen (da gibt es die Antwort in den von Dir verwiesenen Seiten) sondern ich will die Breite eines Bildes vor dem Upload aus dem Uploadformular auslesen sobald es dort selektiert wurde.  Meine Fragen deshalb:
              Kennst Du dieses Problem und hast Du es gelöst?
              Steht die Antwort in einer von Dir verwiesenen Seite?

              Vielen Dank
              LG
              Gerold

              1. Hallo Gerold.

                […] ich will die Breite eines Bildes vor dem Upload aus dem Uploadformular auslesen sobald es dort selektiert wurde.

                Das ist meines Wissens nicht möglich.

                Einen schönen Montag noch.

                Gruß, Ashura

                --
                sh:( fo:} ch:? rl:( br: n4:~ ie:{ mo:| va:) de:> zu:} fl:( ss:) ls:[ js:|
                „It is required that HTML be a common language between all platforms. This implies no device-specific markup, or anything which requires control over fonts or colors, for example. This is in keeping with the SGML ideal.“
                [HTML Design Constraints: Logical Markup]
                1. Hell-O!

                  […] ich will die Breite eines Bildes vor dem Upload aus dem Uploadformular auslesen sobald es dort selektiert wurde.
                  Das ist meines Wissens nicht möglich.

                  Es geht prinzipiell:

                  function test_me() {  
                    var url = document.Formular.bild.value;  
                    var img = new Image();  
                    img.onload = function() { alert(this.width+" x "+this.height); };  
                    img.onerror = function() { alert(this.src + " ist keine Grafikdatei!"); };  
                    img.src = url;  
                  }
                  

                  Funktioniert hier bei mir im Opera 8 und im IE 6. Nur der FF zickt herum, ist aber bestimmt nur eine Einstellungssache, die ich zu faul zu suchen bin :-)

                  Siechfred

                  --
                  Hier könnte Ihre Werbung stehen.
                  Dark Millennium || Die neue 1%-Regelung
                  1. Hallo Siechfred.

                    function test_me() {

                    var url = document.Formular.bild.value;
                      var img = new Image();
                      img.onload = function() { alert(this.width+" x "+this.height); };
                      img.onerror = function() { alert(this.src + " ist keine Grafikdatei!"); };
                      img.src = url;
                    }

                      
                    Bist du sicher, dass es nicht so aussehen müsste?  
                      
                    ~~~javascript
                    function test_me() {  
                      var url = document.Formular.bild.value;  
                      var img = new Image();  
                      img.src = url;  
                      img.onload = function() { alert(this.width+" x "+this.height); };  
                      img.onerror = function() { alert(this.src + " ist keine Grafikdatei!"); };  
                    }
                    

                    Auf wessen src, width und height sollte sonst zugegriffen werden?

                    Einen schönen Montag noch.

                    Gruß, Ashura

                    --
                    sh:( fo:} ch:? rl:( br: n4:~ ie:{ mo:| va:) de:> zu:} fl:( ss:) ls:[ js:|
                    „It is required that HTML be a common language between all platforms. This implies no device-specific markup, or anything which requires control over fonts or colors, for example. This is in keeping with the SGML ideal.“
                    [HTML Design Constraints: Logical Markup]
                    1. Hallo Gunnar™.

                      Bist du sicher, dass es nicht so aussehen müsste?

                      Ja, ist er, weil onload sowieso erst nach Abschluss des Ladens der Grafik feuert.

                      Einen schönen Montag noch.

                      Gruß, Ashura

                      --
                      sh:( fo:} ch:? rl:( br: n4:~ ie:{ mo:| va:) de:> zu:} fl:( ss:) ls:[ js:|
                      „It is required that HTML be a common language between all platforms. This implies no device-specific markup, or anything which requires control over fonts or colors, for example. This is in keeping with the SGML ideal.“
                      [HTML Design Constraints: Logical Markup]
          2. auch mit "document.getElementById("beispiel").onload = function ()..." funktioniert es nicht.

            Was heißt das?

            Struppi.

            --
            Javascript ist toll (Perl auch!)