I’m trying to resize an image at runtime in yii, but does not work.
I tried this code in the view but it does not work.
My code in view.php
header('Content-Type: image/jpeg');
$image = imagecreatefromjpeg('image.jpg');
echo imagejpeg($image);
My code in controller
public function actionImage()
{
$this->render('image');
}
Output html
<html debug="true">
<body style="margin: 0px; ">
<img style="-webkit-user-select: none; " src="http://localhost/yiiadministration/index.php?r=administration/products/image"/>
</body>
<script src="chrome-extension://bmagokdooijbeehmkpknfglimnifench/googleChrome.js"/>
</html>
P.S; the code in the view is just to see the operation, and not to scale the image, because I normally do this in php.
Can anyone help?
A header has already been sent before the view is rendered so your code tries to send a new header and fails as it has already been sent.
You can either send that header from the controller or use an img tag in the view as said previously on stack overflow here
Also imagejpeg() outputs the image directly to the browser so the echo is wrong in that context.