1: <?php
2: /**
3: * Description of Img
4: *
5: * @author SARTAJ
6: */
7: namespace Sphp\Comp\Html{
8:
9: class Img extends \Sphp\tools\Component{
10:
11: protected function oninit() {
12: $this->tagName = "img";
13: $this->unsetEndTag();
14: //$this->unsetSubmit();
15: }
16:
17:
18: protected function onrender(){
19: $sphp_settings = getSphpSettings();
20: $basepath = $sphp_settings->base_path;
21: if($this->value!=''){
22: $this->setAttribute('src', $this->value);
23: }
24: if($this->getAttribute('src')!='' && $this->getAttribute('width')!=''){
25: $size = getimagesize(str_replace($basepath, '',$this->getAttribute('src')));
26: $size0 = $size[0];
27: $size1 = $size[1];
28: $aspectratio = $size0/$size1;
29: $width = $this->getAttribute('width');
30: $height = $width / $aspectratio;
31: $this->setAttribute('height', strval($height));
32: }
33:
34: }
35:
36: // javascript functions used by ajax control and other control
37: public function getJSValue(){
38: return "document.getElementById('$this->name').value" ;
39: }
40:
41: public function setJSValue($exp){
42: return "document.getElementById('$this->name').value = $exp;" ;
43: }
44:
45: public function getJSSrc(){
46: return "document.getElementById('$this->name').src" ;
47: }
48:
49: public function setJSSrc($exp){
50: return "document.getElementById('$this->name').src = $exp;" ;
51: }
52:
53: }
54: }
55: