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

  • SEARCH
  • Home
  • 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 8084385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:46:48+00:00 2026-06-05T17:46:48+00:00

I am testing a thumbnail image creator script which creates a thumbnail that can

  • 0

I am testing a thumbnail image creator script which creates a thumbnail that can be displayed in the web browser without saving it first.

Currently I have to use the following code to display the image:

include('image.inc.php');

    header('Content-Type: image/png');
    create_thumbnail('me.jpg', false, 200, 200);

But how can I display the dynamically generated thumbnail image on a standard webpage along side html mark-up?

create_thumbnail function:

function create_thumbnail($path, $save, $width, $height){

    // Get the width[0] and height[1] of image in an array
    $info = getimagesize($path);

    // Create a new array that just contains the width and height
    $size = array($info[0], $info[1]);

    // Check what file type the image is
    if($info['mime'] == 'image/png'){

        $src = imagecreatefrompng($path);

    }else if($info['mime'] == 'image/jpeg'){

        $src = imagecreatefromjpeg($path);

    }else if($info['mime'] == 'image/gif'){

        $src = imagecreatefromgif($path);

    }else{
        // If it isn't a good file type don't do anything
        return false;
    }

    // Create a thumbnail with the passed dimensions
    $thumb = imagecreatetruecolor($width, $height);


    $src_aspect = $size[0] / $size[1];

    $thumb_aspect = $width / $height;

    if($src_aspect < $thumb_aspect){

        // Image is tall
        $scale = $width / $size[0];
        $new_size = array($width, $width / $src_aspect);
        $src_pos = array(0, ($size[1] * $scale - $height) / $scale / 2);
    }else if($src_aspect > $thumb_aspect){

        // Image is wide
        $scale = $height / $size[1];
        $new_size = array($height * $src_aspect, $height);
        $src_pos = array(($size[0] * $scale - $width) / $scale /2, 0);

    }else{

        // Image is square
        $new_size = array($width, $height);
        $src_pos = array(0, 0);
    }

    // Stop the new dimensions being less than 1 (this stops it breaking the code). Takes which ever value is higher.
    $new_size[0] = max($new_size[0], 1);
    $new_size[1] = max($new_size[1], 1);


    // Copy the image into the new thumbnail 
    // Newly created thumbnail, image copying from, starting x-coord of thumbnail, starting y-coord of thumbnail(0,0 will fill up entire thumbnail), x-coord of original image, y-coord of original image,  width of new thumbnail, height of new thumbnail, width of original image, height of original image
    imagecopyresampled($thumb, $src, 0, 0, $src_pos[0], $src_pos[1], $new_size[0], $new_size[1], $size[0], $size[1]);

    if($save === false){
        return imagepng($thumb);
    }else{

    // Create the png image and save it to passed location
    return imagepng($thumb, $save);
    }
  • 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-05T17:46:51+00:00Added an answer on June 5, 2026 at 5:46 pm

    Convert it to base64 (using base64_encode) and then display it with:

    <img src="data:image/jpg;base64,iVBORw0KGgoAAAANS==" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a single image upload/crop/resize script for files up to 10MB. When testing,
How can I have text appear when hovering a thumbnail image - I've found
I am trying to create and save a thumbnail image when saving the original
Testing in various versions of Firefox new and old it seems that column-span in
Duplicate: Testing a website for cross-browser/multiple-version support How do you test visual components I
During testing, I'm stuck with testing a piece of code that receives a list
For testing purposes I have this shell script #!/bin/bash echo $$ find / >/dev/null
What I'm trying to do is create a class that I can quickly attach
Testing can be mainly classified into manual and automated testing. With regard to this
Testing a couple of compilers (Comeau, g++) confirms that the result of a bitwise

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.