S
S
samorez7772018-03-19 04:58:08
PHP
samorez777, 2018-03-19 04:58:08

Is it possible to get text from mysql and overlay it on a picture, and save it as a jpg?

It is necessary to display the text from the fields from Mysql using the code and save the text to a jpg image, save the file with the name of the product. There are about 40 items in the database. You need a separate jpg file for each product.
Database structure: mybd => shop => id, name , price . Text to insert into the picture: product name and price.
I have a code please help me

<?php
header('Content-type: image/jpeg');

// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('img.jpg');

// Allocate A Color For The Text
$white = imagecolorallocate($jpg_image,255,255,255);

// Set Path to Font File
$font_path ='E:\serv\OSPanel\domains\localhost\verdana.ttf';

// Set Text to Be Printed On Image
$text ="$name";
$text2 ="$price";

// Print Text On Image
imagettftext($jpg_image,25,0,75,300, $white, $font_path, $text);
imagettftext($jpg_image,25,0,100,400, $white, $font_path, $text2);


// Send Image to Browser
imagejpeg($jpg_image,"$name.jpg");

// Clear Memory
imagedestroy($jpg_image);?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hardcorelite, 2018-03-20
@hardcorelite

$img="images/bilet.jpg";
$pic = ImageCreateFromjpeg($img); //открываем рисунок в формате JPEG
Header("Content-type: image/jpeg"); //указываем на тип передаваемых данных
$color=ImageColorAllocate($pic, 250, 0, 0); //получаем идентификатор цвета
/* определяем место размещения текста по вертикали и горизонтали */
$h = 260; //высота
$w = 220; //ширина
/* выводим текст на изображение */
ImageTTFtext($pic, 26, 0, $w, $h, $color, "Times", "Simona");
ImageTTFtext($pic, 26, 0, $w-50, $h+65, $color, "Times", time());
Imagejpeg($pic,"images/".time().".jpg"); //сохраняем рисунок в формате JPEG
ImageDestroy($pic); //освобождаем память и закрываем изображение

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question