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 653093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:20:38+00:00 2026-05-13T22:20:38+00:00

This is a contrived example, but it illustrates my problem much more concisely then

  • 0

This is a contrived example, but it illustrates my problem much more concisely then the code I’m using – and I’ve tested this and it exhibits the problem:

$image = imagecreatefromjpeg('test.jpg');    
$copy_of_image = $image;

// The important bit
imagedestroy($image);

header('Content-type: image/jpeg');
imagejpeg($copy_of_image);

Now, my expectation is that $copy_of_image is exactly that, but when I run this, it fails, printing out the URL of the script of all things. Comment out the imagedestroy() and it works just fine.

a var_dump of $image provides:

resource(3) of type (gd) 

So why can’t I copy this? Apparently the assignment $copy_of_image = $image is creating a reference rather then a copy – is there a way to prevent that?

  • 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-05-13T22:20:39+00:00Added an answer on May 13, 2026 at 10:20 pm

    The resource itself is a reference to an image. So, whether you copy or reference-assign it to another variable, the resource still references the same image. You’re just making two references that both point to the same image. If you destroy the image (that’s what imagedestroy does), the image is no longer available and any resource pointing to it becomes invalid.

    You would need to create a new image with imagecreatetruecolor and copy the contents of the first image to the second using imagecopy. Or create two separate images with two separate resources using imagecreatefromjpeg in the first place.

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

Sidebar

Related Questions

I realize this is a contrived example, but I want a compile check to
I realize this is a very contrived example, but I've simplified the full version
Contrived example, but with 'code first' EF4 could I store in the database a
This is a contrived example, but lets say I have declared objects: CustomObj fooObj;
This may seem like a somewhat contrived example, but I'm left scratching my head.
Consider this contrived, trivial example: var foo = new byte[] {246, 127}; var bar
I know this is a contrived example so please do not jump all over
Consider this contrived example. The following array works fine if I want to convert
In this very contrived example, I have an array with 3 elements that I'm
This is a somewhat contrived example meant to show a point. Here are two

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.