LaszloR1
LaszloR1

Reputation: 129

Changing the html title of a PHP created image

I have a php script that generates images from a URL and displays them as images with the correct header. The problem I've ran into is that I cannot change the filename/title that is displayed in the browser tab. It will display "file.php" as the title. If I try to specify the title with tags before creating the image it will cause errors and the image won't be displayed at all.

PDFs have an option to set the title, I tried to look for header titles, but couldn't find any.

This is the code, the title will show what .php file it is saved as. I would like to specify a title for the image either before or after creation.

    header('Content-Type: image/png');
    $im = imagecreatefrompng('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png');
    imagepng($im);
    imagedestroy($im);

Upvotes: 1

Views: 1083

Answers (1)

abdusco
abdusco

Reputation: 11091

Add a new Content-Disposition header and set the filename there

header('Content-Disposition: inline; filename="image.png"');

Specify inline parameter to not force browsers to download the file, or replace inline with attachment to force download

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Directives

Upvotes: 3

Related Questions