Post by prototype0104 » Thu Nov 28, 2019 11:12 pm

Hi guys! I know that is not OC related, sorry but I don't find a solution. I'm created a script for generate coupon image with customer name but I can't save the image on the host to send it by email..

Code: Select all

$im = imagecreatefromjpeg($imagine);
// Fetching Sizes of the Image
$sizes = getimagesize($imagine);

// Main BOX
$box = new Box($im);
// Setting Up Font for editing
$box->setFontFace('font.ttf');
$box->setFontColor(new Color(255, 255, 255));
$box->setTextShadow(new Color(0, 0, 0, 50), 2, 2);
$box->setFontSize('62');
// Setting Up Margin
$box->setBox(20,20, $sizes[0]- 40, $sizes[1]-40);
// Text Alignment
$box->setTextAlign('center', 'center');
$box->draw($_POST['status']);


// WaterBox
$waterbox = new Box($im);
// Setting Up Font for editing
$waterbox->setFontFace('font.ttf');
$waterbox->setFontColor(new Color($r, $g, $b));
$waterbox->setTextShadow(new Color($sr, $sg, $sb, 50), 2, 2);
$waterbox->setFontSize(30);
// Setting Up Margin
$waterbox->setBox(20,20, $sizes[0]- 40, $sizes[1]-40);
// Text Alignment


// Changing Header Information for treating this page as an image.

$im->save('catalog/voucher.jpeg');
Fatal error: Uncaught Error: Call to a member function save() on resource

Any idea?

Active Member

Posts

Joined
Sun Mar 24, 2019 6:08 pm

User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by prototype0104 » Fri Nov 29, 2019 9:42 pm

Thank you! This worked, did someone used composer in controller file?

Code: Select all

require_once(DIR_STORAGE . 'vendor/autoload.php');

use GDText\Box;
use GDText\Color;

function vouchercreate($pret)
{
// Carving RGB codes out of HEX codes
list($r, $g, $b) = sscanf($_POST['color'], "#%02x%02x%02x");
list($sr, $sg, $sb) = sscanf($_POST['shadowcolor'], "#%02x%02x%02x");
            $imagine= "blank.jpg";             
// Making a Image Object
$im = imagecreatefromjpeg($imagine);
// Fetching Sizes of the Image
$sizes = getimagesize($imagine);

// Main BOX
$box = new Box($im);
// Setting Up Font for editing
$box->setFontFace('font.ttf');
$box->setFontColor(new Color(255, 255, 255));
$box->setTextShadow(new Color(0, 0, 0, 50), 2, 2);
$box->setFontSize('62');
// Setting Up Margin
$box->setBox(20,20, $sizes[0]- 40, $sizes[1]-40);
// Text Alignment
$box->setTextAlign('center', 'center');
$box->draw("LEI");


// WaterBox
$waterbox = new Box($im);
// Setting Up Font for editing
$waterbox->setFontFace('font.ttf');
$waterbox->setFontColor(new Color($r, $g, $b));

// Setting Up Margin
$waterbox->setBox(20,20, $sizes[0]- 40, $sizes[1]-40);
// Text Alignment

imagejpeg($im, '/home/ratv2191/public_html/admin/controller/sale/voucherfinal.jpg');

}
I want to use this function in the controller file.. Image is saved but is not edited. Basically is saving the blank.jpg image

If I'm running this script is working.

EDIT:
I just access the script for generate image with a link from controller and got the parameter with $_GET.
DONE :D

Active Member

Posts

Joined
Sun Mar 24, 2019 6:08 pm
Who is online

Users browsing this forum: Cachly81ngay and 41 guests