同じ問題がありました。ヒントをありがとうございます。既存の画像関数を寸法を尊重する関数に置き換えるプラグインは次のとおりです。http: //jsfiddle.net/drzaus/dhkh7/
安全のために、元の画像関数が変更された場合に備えて、おそらく元の画像関数を上書きしないでください。
;(function(Raphael){
/// Plugin - replaces original RaphaelJS .image constructor
/// with one that respects original dimensions.
/// Optional overrides for each dimension.
/// @drzaus @zaus
/// based on http://stackoverflow.com/questions/10802702/raphael-js-image-with-its-original-width-and-height-size
var originalRaphaelImageFn = Raphael.fn.image;
Raphael.fn.image = function(url, x, y, w, h) {
// fix the image dimensions to match original scale unless otherwise provided
if( !w || !h ) {
var img = new Image();
img.src = url;
if( !w ) w = img.width;
if( !h ) h = img.height;
}
return originalRaphaelImageFn.call(this, url, x, y, w, h);
};
})(Raphael);
そして使用法:
window.onload = function() {
var paper = new Raphael('canvas', '100%', '100%');
// specify dimensions as before
paper.image('http://www.stockfreeimages.com/Swiss-panorama-thumb6499792.jpg', 10, 10, 100, 50).attr('stroke', '#000');
// original ratio
paper.image('http://www.stockfreeimages.com/Swiss-panorama-thumb6499792.jpg', 10, 100).attr('stroke', '#f00');
// specify width, height taken from original
paper.image('http://www.stockfreeimages.com/Swiss-panorama-thumb6499792.jpg', 10, 200, 100).attr('stroke', '#0f0');
// specify height, width taken from original
paper.image('http://www.stockfreeimages.com/Swiss-panorama-thumb6499792.jpg', 10, 300, false, 100).attr('stroke', '#00f');
};