John Davidson

html - Cannot display JPEG image in PHP Laravel project

0 comments
Message:


Does anybody know what can call these files properly?


I'm trying to put text on a JPEG image, and apparently the way I'm calling those 2 files is not working


It is a PHP 7.4 Laravel 8 project and the script is located in a blade view.




<?php


// C:\xampp\htdocs\solidcadclass\public\storage\resources\arial.ttf
// C:\xampp\htdocs\solidcadclass\public\storage\resources\template.jpeg

$img = imagecreatefromjpeg('C:\xampp\htdocs\solidcadclass\public\storage\resources\template.jpeg');

$black = imagecolorallocate($img, 0, 0, 0); // OBJ, RGB
$txt = Auth::user()->name;
$font = 'C:\xampp\htdocs\solidcadclass\public\storage\resources\arial.ttf';

imagettftext(
$img, // Image object
24, // Font Size
0, // Angle
5, 24, // x,y
$black, // Color
$font, // Font to use
$txt // Text to write
);

// OUTPUT IMAGE
header("Content-type: image/jpeg");
imagejpeg($img);


My Answer:
To display a JPEG image in a PHP Laravel project, you can use the following code in your blade view:

html
Image


Make sure to replace `'path/to/your/image.jpg'` with the actual path to your JPEG image file. The `asset()` helper function is used to generate the URL for the image file.

If you are trying to overlay text on the image, you can use CSS to position the text on top of the image. Here is an example:

html

Image

Your text here




This code will overlay the text on the center of the image. You can adjust the positioning and styling of the text as needed.

If you are still having trouble displaying the JPEG image, make sure that the path to the image file is correct and that the file permissions are set correctly to allow the web server to access the file.

Rate this post

3 of 5 based on 1169 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us