Clickable links imagecreatefrompng - php

At this moment i'm trying to create a dynamic PHP image, and i'm not really sure if it is even possible to have clickable links in the following piece of code:
<?php
$image = "hotelview_val13.png";
$src = 'pixel.png';
putenv('GDFONTPATH=' . realpath('.'));
$font = 'font.ttf'; //Ubuntu font
$im = imagecreatefrompng($image);
imagealphablending($im, true);
imagesavealpha($im, true);
imagealphablending($src_to_copy, true);
imagesavealpha($src_to_copy, true);
imagealphablending($pg, true);
imagesavealpha($pg, true);
$wc = ImageColorAllocate ($im, 255, 255, 255);
$red = ImageColorAllocate ($im, 255, 0, 0);
$blk = imagecolorallocate($im, 0, 0, 0);
{
imagettftext($im, 12, 0, 45, 310, $blk, $font , "Link");
imagettftext($im, 12, 0, 45, 330, $blk, $font , "Veel plezier ;)");
}
header("Content-Type: image/png");
Imagepng($im);
ImageDestroy ($im);
?>
What i'm trying to do is to make a clickable link. I've tried to just simply put into the code, but that doesn't work because it displays the code as plain text. Is it possible? If it is, how does it work?
Thanks a lot for your time.

You cannot embed links in an image. The only way to make a region of an image clickable is, when viewed in a browser, to use an HTML map.

Related

I have code that works, with picture uploaded from gimp. But image created with gd not

My problem is this, I want to create image thats combination of 3 image, first is yellow background, then I use PHP and GD to write some text on it, text is black, so I made it transparent in next step, then I want to put that picture over background picture, so text has texture on it. It works fine, if I upload PNG from my computer created in Gimp, but picture created with gd has transparency on it but result is again yellow background with black letters.
how it should be
good result
what I get now from code:
enter link description here
how it gets now with image created from gd
<?php
header('Content-Type: image/png');
$title = "PULEŽANI";
$im = imagecreatetruecolor(1200, 320);
//$im = imagecreatetruecolor(1200, 320);
$white = imagecolorallocate($im, 255, 255, 255);
$crna = imagecolorallocate($im, 0, 0, 0);
$black = imagecolorallocatealpha($im, 255, 255, 255, 127);
$yellow = imagecolorallocate($im, 251, 189, 8);
// kreiram kvadrat sa žutom pozadinom
imagefill($im, 0, 0, $yellow);
$font = "/AlrightSans-Ultra-v3.ttf";
//dodajem text na žutu pozadinu
imagettftext($im, 122, 0, 40, 160, $crna, $font, $title);
//kreiram sliku crni tekst na žutoj pozadini
imagepng($im, 'sl.png');
imagedestroy($im);
//ovaj dio bi trebao napraviti da crna slova postanu prozirna
$image = imagecreatefrompng('sl.png');
$odabirprozirne = imagecolorallocatealpha($image, 0, 0, 0,127);
imagealphablending($image, true);
imagecolortransparent($image,$odabirprozirne);
imagepng($image, 'sl114.png');
imagedestroy($image);
/* dodaj zvijezde odispod */
$image_1 = imagecreatefrompng('TexturaZvijezde.png');
$image_2 = imagecreatefrompng('sl114.png');
imagesavealpha($image_1, true);
imagecopy($image_1, $image_2, 0, 0, 0, 0, 1200, 120);
imagepng($image_1);
imagedestroy($image_1);
I haven't tested this, but according to the manual for imagesavealpha function,
You have to unset alphablending (imagealphablending($im, false)), to use it.
Example:
// Turn off alpha blending and set alpha flag
imagealphablending($png, false);
imagesavealpha($png, true);

cant change font type in dynamic image

cant seem to get the font to work , so far i've seen that the imagestring doesn't support the font being changed so im trying to work with imagettftext like so
imagettftext($finalImage, 20, 0, 11, 21, $textcolorBlue, $font2, $text);
but instead of displaying any text , it just shows the image with all the imagestring's written , also this is my first time working with dynamic images so , im not quite sure what im doing wrong (if any thing) also Neverwinter.ttf is in the same file directory as the image script any help would be appriciated
<?php
$image = imagecreatefrompng("icons.png");
imagesavealpha($image, true);
imagealphablending($image, true);
$size = getimagesize("icons.png");
$finalImage = imagecreatetruecolor(320,125);
$font = imageloadfont('/runescape/phpfile/arial.ttf');
$font2 = imageloadfont('Neverwinter.ttf');
$font = 4;
$textcolorBlack = imagecolorallocate($finalImage, 0, 0, 0);
$textcolorWhite = imagecolorallocate($finalImage, 255, 255, 255);
$textcolorGreen = imagecolorallocate($finalImage, 0, 255, 0);
$textcolorBlue = imagecolorallocate($finalImage, 225,225, 255);
imagecopy($finalImage, $image, 0, 0, 0, 0, 320, 125);
//imagestring($finalImage, $font, 0, 0, 'random', $textcolorBlue);
$text = 'testing...';
imagettftext($finalImage, 20, 0, 11, 21, $textcolorBlue, $font2, $text);
// Content type
header('Content-type: image/png');
imagepng($finalImage);
?>
just change the line
$font2 = imageloadfont('Neverwinter.ttf');
to
$font2 = 'path/Neverwinter.ttf';

Create image in gd library

I am copying image over an image using GD library But it is not showing properly. This is my code:
<?php
$im = imagecreate(288,288);
$background_color = imagecolorallocate($im, 230, 248, 248);
$file = 'images/smiley/smile'.$_POST['smiley'].'.png';
$bg = imagecreatefrompng($file);
imagealphablending($bg, true);
imagesavealpha($bg, true);
imagecopymerge($im, $bg, 10, 10, 0, 0, 100, 47, 25);
?>
i cannot upload image due to not enough reputation but i can explain that when i have a smiley where i have to overlap over an other image but when i run this function a grey color box overlap on the image instead of smiley. Smiley is also in grey color.
Please help...
This is the link for the image create after function runs
http://classicsouls.com/main/9695.png
I want to overlap this image
http://classicsouls.com/main/smile7.png
Try to set imagealphablending also for $im:
$im = imagecreate(288,288);
imagealphablending($im, true);
$background_color = imagecolorallocate($im, 230, 248, 248);
$file = 'images/smiley/smile'.$_POST['smiley'].'.png';
$bg = imagecreatefrompng($file);
imagealphablending($bg, true);
imagesavealpha($bg, true);
imagecopymerge($im, $bg, 10, 10, 0, 0, 100, 47, 25);

I can't use transparent background with imagecopymerge

I am calling imagecopymerge($dst_r, $logo, 0, 0, 0, 0, $LogoX, $LogoY, 100); where $logo is a png file with transparent background. From some reason the background comes out white instead.
What am I doing wrong?
Thanks.
You need to use imagealphablending($dst_r, TRUE); to allow copying with retaining the transparent colors. Many more comments (...) in the manual suggest using imagecopy instead, because imagecopymerge was never intended to be used with transparency. If you use pct=100 anyway, then the normal imagecopy might be an option.
This is for text, but you can get the point. It would be more helpful if you post entire code.
$font = 25;
$string = "Hello";
$im = #imagecreatetruecolor(strlen($string) * $font / 1.5, $font);
imagesavealpha($im, true);
imagealphablending($im, false);
$white = imagecolorallocatealpha($im, 255, 255, 255, 127);
imagefill($im, 0, 0, $white);
$lime = imagecolorallocate($im, 204, 255, 51);
imagettftext($im, $font, 0, 0, $font - 3, $lime, "font.ttf", $string);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);

Outputting image with underlined text using php GD library

What is the best way to display underlined text and output the result as image with GD or any other library?
You can try using the Unicode underline combining character U+0332.
<?php
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = "̲U̲d̲e̲r̲l̲i̲n̲e";
// Replace path by your own font path
$font = 'arial.ttf';
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
There are lots of FREE PHP CAPTCHA out there that come with a lot of customization, download one and see what exactly happens behind the scene. Also have a look at this link
HTH
I am using this...
$font = imageloadfont($font_file);
$font_width = ImageFontWidth($font);
$font_height = ImageFontHeight($font);
$str_width = strlen($text)*$font_width;
ImageLine($image, $left, $top+$font_height, $left+$str_width, $top+$font_height, $color);

Categories