Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9053459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:25:35+00:00 2026-06-16T13:25:35+00:00

I tried this imagejpeg() php method, but it returns an image to a browser

  • 0

I tried this imagejpeg() php method, but it returns an image to a browser on running the code.

However I need a method that returns an image URL so that i can use it in my img tag.

Currently i have to use –

<img src="siteurl/myphpfile.php" />

but i think its better if the method returns an image handler so that i can use it in my img tag, like –

<img src="image.jpg" />

My myphpfile.php is the file that contains the code.

Searched many functions at php manuals but no luck, I am also using this method imagettftext() for text addition over image.

Total code in the File —

<?php
    function myimagecreate( $myname ) {
    $headurl = 'template_header01.jpg';
    header('Content-type: image/jpeg');
    $text = "My Full Text";
    $name = $text.".jpg";
    $jpg_image = imagecreatefromjpeg($headurl);
    $black = imagecolorallocate($jpg_image, 1, 1, 1);
    $font_path = 'myfont/arial.ttf';
    imagettftext($jpg_image, 24, 0, 175, 85, $black, $font_path, $text);
    imagejpeg($jpg_image,'mynameimg.jpg');
    imagedestroy($jpg_image);
    return 'mynameimg.jpg';
    }

    $to = 'swapnesh20032003@gmail.com';
    $subject = $myname; 
    $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kings</title>
</head>

<body>
<table width="100%"><tr><td valign="bottom" align="center" height="282"><img src="'.myimagecreate( $myname ).'" /></td></tr></table></table></body></html>';

mail($to,$subject,$message);    
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:25:36+00:00Added an answer on June 16, 2026 at 1:25 pm

    There are 2 more obvious ways to approach this problem.

    1. Write the rendered image to a file

      This is possible using imagejpeg, by passing in a second parameter of the filename, for example:

       $im = imagecreatetruecolor(..);
       // ..
       imagejpeg($im, 'image.jpg');
      
    2. Use URL Rewriting

      You can always pass through all .jpgs in a special folder (for example /dynamic/image.jpg through to your script which will render it). If you want, you could even take the filename (image.jpg) as a parameter to your script telling it what to render if the image is dynamic.

    Obviously, if your image needs to be different per request, #2 is the better option. However, #1 is faster and recommended if your image is static (ie. your imagettftext always writes the same text over the same image).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried this, but could not get through:- code behind protected HtmlTableRow trComment; protected
This is my php code which is only fetching the first image out of
I'm using this php code in image.php file to merge a png image with
I tried this code from the post, but this code is sending two emails
I tried this here: http://jsfiddle.net/92HXT/1/ but it does not work. It only works if
I tried this code to open a file in Python: f = open("/Desktop/temp/myfile.txt","file1") It
I tried this so far: <?php $error = ; $conn = pg_connect(host=localhost dbname=brittains_db user=brittains
I tried this aproach without any success the code I'm using: // File name
Possible Duplicate: How to resize an image using PHP? Here's what I've tried: $image
I've been trying to resize an image using php but I'm having issues getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.