raphael's clip-rect property to get result on generated svg image

为君一笑 提交于 2020-01-06 13:04:30

问题


i have an image on my canvas in Raphael and i use clip-rect to crop parts that i dont need. Now i have generated a svg with raphael.serialize plugin, but i cannot get clip-rect working. thet part from php script that loop over created json:

for ($i=0; $i <= count($json); $i++) {
            if ($json[$i]['type'] == "image" ) {
                $base64 = base64_encode(file_get_contents($json[$i]['src']));
                $output .= '<image overflow="visible" x="'.$json[$i]["x"].'" y="'.$json[$i]["y"].'" width="'.$json[$i]["width"].'"  clip-rect="'.$json[$i]["clip"].'" height="'.$json[$i]["height"].'" transform="'.$json[$i]["transform"].'" preserveAspectRatio="none" xlink:href="data:image/png;base64,'.$base64.'"></image>';
          }
    }

and here some part of modified serialize plugin:

var object = {
                  type: node.type,
                  width: node.attrs['width'],
                  height: node.attrs['height'],
                  x: node.attrs['x'],
                  y: node.attrs['y'],
                  src: node.attrs['src'],
                  clip: node.attrs['clip-rect'],
                  transform: node.transformations ? node.transformations.join(' ') : ''
                }

i have tried to use viewBox="'.$json[$i]["clip"].'" and clip="'.$json[$i]["clip"].'" but i get no result.

how can i get this thing working?


回答1:


There is no 'clip-rect' attribute in SVG. There is however a 'clip-path' attribute, which is what Raphaël actually uses (clip-rect is just an abstraction/limitation). Note that you will need to serialize the <clipPath> that defines the clipping region too.



来源:https://stackoverflow.com/questions/8129995/raphaels-clip-rect-property-to-get-result-on-generated-svg-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!