Tweak inline image styling to divide max-width by half

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
Najphp
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Jul 14, 2018 3:47 am

Sat Jul 14, 2018 4:00 am

Hello.

I'm not a PHP coder (more frontend dev) but I've been tasked with tweaking some PHP.

Specifically, the client wants to upload double-sized images but still get the image to display at the original size.

At the moment, when an image is uploaded (via a custom image manager) the width of the image is noted and an inline style is generated within a file called ajax_actions.php:

Code: Select all

$obj = new Image($id);

<img src="'.$obj->src().'" title="'.$obj->artist().'" style="max-width:'.$obj->width().'px;"/>
The bit I'm interested in is this:

Code: Select all

style="max-width:'.$obj->width().'px;"
Is there any way of introducing a calculation to halve the size of the uploaded image into the empty brackets following width, e.g.

Code: Select all

$obj->width(/2)
?

Any help would be much appreciated :D

element121
php-forum Fan User
php-forum Fan User
Posts: 628
Joined: Sat Jun 06, 2015 11:46 am
Contact:

Mon Jul 16, 2018 10:35 am

Not in the brackets, but just after:

Code: Select all


$obj->width() / 2 


Najphp
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Jul 14, 2018 3:47 am

Mon Jul 16, 2018 1:09 pm

Great - thanks a lot!

Post Reply