Help get this topic noticed by sharing it on Twitter, Facebook, or email.
I’m looking forward to seeing others custom variables

Add size attributes variable for all images

I ran into an issue where I needed to set the size of some images inline. To get something like this:


<img src="imgfile.jpg" width="300" height="200" />


All you need is add some code into app/asset-type/image.inc.php. These lines can go at the end of function set_extended_data($file_path), right after $large_relative_path statement.


# set dimensions for image
$img_path = preg_replace('/
# set dimensions for image
$img_path = preg_replace('/\.\.\//', '', $this->link_path);
$img_size = getimagesize($img_path);
$this->data['@sizeattrs'] = $img_size[3];
#46;
# set dimensions for image
$img_path = preg_replace('/\.\.\//', '', $this->link_path);
$img_size = getimagesize($img_path);
$this->data['@sizeattrs'] = $img_size[3];
#46;
# set dimensions for image
$img_path = preg_replace('/\.\.\//', '', $this->link_path);
$img_size = getimagesize($img_path);
$this->data['@sizeattrs'] = $img_size[3];
#47;/', '', $this->link_path);
$img_size = getimagesize($img_path);
$this->data['@sizeattrs'] = $img_size[3];


Now you can use @sizeattrs to output the size attributes in your image tag like so:


<img src="@url" @sizeattrs />
6 people like
this idea
+1
Reply