SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: .jpg as .php

  1. #1
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Miami, Florida - Caracas, Venezuela
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .jpg as .php

    Can I make PHP process files ending with .jpg (or any other extension) as if they where .php files?

    Let's say, for example, I wanted to have a script that added a copyright (using GD) to certain images when these are requested by someone other than our server. I want to have that script be referenced like this:Then I would explode the requesting URI to extract:
    Code:
    category
    manufacturer
    model
    and use these as variables to retrieve the image (or build it on the fly).

    Any thoughts?

    Thank you,
    Luis

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't know but it's a good question. Try it. What I do know from experimenting right now is that the JPG can't have the extra data when it gets to the browser. But it's hypothetically possible to parse the data, strip it out so when it gets to the browser it is in the exact binary format it would normally be. But it's all hypothetical and guess work. Give it a whirl and see what happens.
    Aaron Brazell
    Technosailor



  3. #3
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.platinum-central.com/temp/image.jpg

    Just add this to .htaccess...

    <Files image.jpg>
    ForceType application/x-httpd-php
    </Files>

    and remember to tell the browser what type of file it is using: header("Content-type: image/jpg");

  4. #4
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah that's what you're doing, eh?
    Aaron Brazell
    Technosailor



  5. #5
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup Was playing around with it the other day (actually that's a .png, but we'll ignore that fact no one will ever know)

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you elaborate on how you did it? Keep in mind thqat png's are a different filetype than JPG's. Are you sure it works with JPGs?
    Aaron Brazell
    Technosailor



  7. #7
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Miami, Florida - Caracas, Venezuela
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, that's exactly what I needed to know.

    Here's something you can try (I was just using it to test):
    PHP Code:
    <?php
    $im 
    ImageCreate(75,350);
    $white ImageColorAllocate($im,0xFF,0xFF,0xFF);
    $black ImageColorAllocate($im,0x00,0x00,0x00);
    ImageTTFText($im,10,90,28,300,$black,'/usr/share/fonts/ja/TrueType/ariali.ttf',$_GET['text']);
    header('Content-Type: image/jpeg');
    ImageJPEG($im);
    ?>
    Needless to say you can use whatever code you want. Just make sure you have the GD extension installed phpinfo() will tell you. You can find more info on this extension here: http://www.boutell.com/gd/

    Now I'll just add the script to a directory with an .htaccess file and that's it!

    Thank you very much,
    Luis

  8. #8
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sketch
    can you elaborate on how you did it? Keep in mind thqat png's are a different filetype than JPG's. Are you sure it works with JPGs?
    PHP can serve any filetype it wants to, and GD can create JPG, and PNG easily.

    The extension of a file means absolutely nothing to a browser, it is the Content-Type which is sent to the browser which is what detemines what the browser should do with it.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •