[nycphp-talk] Image resizing/cropping on the fly
Bulat Shakirzyanov
mallluhuct at gmail.com
Wed Sep 7 12:56:06 EDT 2011
make sure that there is no whitespace between the colon and the header name,
so
header('Content-type :image/jpeg');
must become
header('Content-type: image/jpeg');
I am not sure how sensitive the browsers are to this, but that's how it
should be formatted according to the HTTP spec.
Additionally, make sure that your image is really and jpeg as if your file
contents was for example PNG or GIF,
the browser would try to process it as a JPEG
There is always Imagine image manupulation library to help you with your
resizing needs - https://github.com/avalanche123/Imagine
Best,
On Wed, Sep 7, 2011 at 9:43 AM, Jake McGraw <jmcgraw1 at gmail.com> wrote:
> If any of the following causes an error and display_errors == 1, you'll get
> output and PHP will default to text/html:
>
> header('Content-type :image/jpeg');
> header('Content-Length: ' . filesize( $image ) );
> $file = file_get_contents( $image );
>
> If you have any whitespace prior to header(), you'll get output and PHP
> will default to text/html.
>
> You can avoid whitespace by never using an ending ?> tag.
>
> Jake
>
> On Wed, Sep 7, 2011 at 12:33 PM, Federico Ulfo <rainelemental at gmail.com>wrote:
>
>> Hi guys,
>>
>> I recently experienced an issue with the image resizing on the fly with GD
>> library of PHP.
>>
>> I draw the image with:
>> header('Content-type :image/jpeg');
>> header('Content-Length: ' . filesize( $image ) );
>> $file = file_get_contents( $image );
>> echo $file;
>> it works when the image is already cached, when I've to create the image,
>> sometimes PHP change my header to Content-type: text/html, so the image
>> won't load, and I'll get instead a list of Ascii.
>>
>> I fixed partially with a workaround, before do the *echo $file;* I check
>> the headers, if they are changed, I remove all of them and set again, also
>> this solution doesn't work always, I also tried to set header( "location: -
>> same location -" ); this works sometimes, because the cache is already
>> created but when there's many images sometimes the browser won't reindex it
>> and give again a blank image.
>>
>> Do you have any idea of why does it?
>>
>>
>>
>>
>> --
>> Federico Ulfo » <http://www.federicoulfo.it/>
>> Certified Developer Google & PHP
>> <http://www.federicoulfo.it/>
>>
>>
>> _______________________________________________
>> New York PHP Users Group Community Talk Mailing List
>> http://lists.nyphp.org/mailman/listinfo/talk
>>
>> http://www.nyphp.org/Show-Participation
>>
>
>
> _______________________________________________
> New York PHP Users Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/Show-Participation
>
--
*Bulat Shakirzyanov* | Software Alchemist
*a: *about.me/avalanche123
*e:* mallluhuct at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20110907/9f493894/attachment.html>
More information about the talk
mailing list