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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:15:18+00:00 2026-06-02T00:15:18+00:00

I’m taking a linked image, and making my own resized versions of them using

  • 0

I’m taking a linked image, and making my own resized versions of them using the imagecopyresampled().

When trying to show GD library resampled images, those below a certain size (around 160px width) show up only as a bunch of gibberish (ex: ‘����JFIF��>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ��C’).

I checked the images themselves, and they were stored fine and show up correctly when opened in a picture viewer. However, printing them to browser just doesn’t work. When I change the pixel size to a larger pixel size, it works fine.

I’m showing the images in the browser like this

$handle = fopen($fileName, "rb");
$img = fread($handle, filesize($fileName));
fclose($handle);
$imgSize = strlen($img);
$image_type = exif_imagetype($fileName);
header('Content-Type: image/JPEG');
header('Content-Transfer-Encoding: binary');
header("Content-Length: $imgSize");
print $img;
return true;

Right now I’m starting to believe it’s something to do with the GD library. Anyone else have any further insight into this?

Thanks.

EDIT:

One of Brad’s suggestions showed me the right way. As usual, it was a completely boneheaded mistake. I can’t answer my own question yet so I figured I’d make an edit instead.

What I forgot to include in my initial description, was that the previous code was all in one of my models, and I then called a function to show the image in my controller.

I’d recently switched to Symfony2, and have been using the Response return pretty much everywhere in my controllers. However, I’d been reusing my old show image code, which had been written without Symfony. I had a “show image” type of function, which I called in my controller and then returned an empty Response. Thus, Symfony’s Response return messed up the encoding. Advanced browsers were able to auto correct for large images, but not for small ones.

My final solution became

In my model

$handle = fopen($fileName, "rb");
$image= fread($handle, filesize($fileName));
fclose($handle);
$image_type = exif_imagetype($fileName);

In my controller

return new Response($image, 200, array('Content-Type' => $image_type));
  • 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-02T00:15:20+00:00Added an answer on June 2, 2026 at 12:15 am

    What you are seeing is the raw image data, which means the browser is, for some reason, not registering the content type.

    What I suspect is happening is that whatever browser you are testing with is case-sensitive to the Content-Type header value.

    Change image/JPEG to image/jpeg, and see if that works for you.

    As for an explanation of why it works with larger images… It is likely that the Content-Type is never being recognized as a known type. Browsers will look at the actual content they received, to try to figure out what type it is. There is probably something in its content sniffing function that looks at small lengths and says, “Nope, probably not an image”, and moves on.

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.