0

I have an external PHP file that does some image resizing (image.php). I need to call it every time a 'image' tag is used so it can fill in the "src". How would I tell the HTML file to use the external PHP page and how would I make it use it when processing the 'image' "src" tag?

This is what im using to try to display the image.

Do i need to include something in my 'head' section?

thanks for the help!

<li><a href= "/intPics//1.jpg"> <img src="<?php loadImage('/intPics//1.jpg', 300,300) ?>"<div>1.jpg</div></a></li>

This is the PHP file

<?php



   function imageResizer($url, $width, $height) {



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



                list($width_orig, $height_orig) = getimagesize($url);



                $ratio_orig = $width_orig/$height_orig;



                if ($width/$height > $ratio_orig) {

                  $width = $height*$ratio_orig;

                } else {

                  $height = $width/$ratio_orig;

                }



                // This resamples the image

                $image_p = imagecreatetruecolor($width, $height);

                $image = imagecreatefromjpeg($url);

                imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height,     $width_orig, $height_orig);



                // Output the image

                imagejpeg($image_p, null, 100);



        }



        /    /works with both POST and GET

        $method = $_SERVER['REQUEST_METHOD'];



        if ($method == 'GET') {



                imageResize($_GET['url'], $_GET['w'], $_GET['h']);



         } elseif ($method == 'POST') {



            imageResize($_POST['url'], $_POST['w'], $_POST['h']);

         }



      // makes the process simpler

        function loadImage($url, $width, $height){

         echo 'image.php?url=', urlencode($url) ,

         '&w=',$width,

         '&h=',$height;

        }



?>

2 Answers 2

2

I don't know if I understood your question correctly but I'll try to answer:

You could call the php script directly from the src in your image tag

<img src="image.php" />

and in your php file you would set the content-type to an image format

<?php header('Content-Type:image/jpeg'); ?>

This way the php script returns an image. You could even pass paramters, e.g. image.php?width=200&height=100 to the php script.

Sign up to request clarification or add additional context in comments.

1 Comment

I posted some code, maybe that can help clarify, sorry its hard to understand. I'm not too sure on how to word my question.
0

I don't know what you have in your php file, but

<?php require_once('path/image.php') ?>

should import it, then you just use the functions and fill the src by a php script?

Edit: If you give me further information, p.e. the code, I can help you witz further questions on details.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.