Running Image Service from PHP

Scenario : Imagine that you want to run an image service and your clients will use these images in their static site developments. The moment you change these in the server it automatically reflect in the client designs.

This is a POC design and can be used in KIOSKS, Web designs etc.

Basically wherever you need the dynamic image you will use image src as a php destination.

<img src=”http://servername.com/image.php” />

Whenever the server receives the request it will serves the image whichever is assigned to that.

Concept:

<?php

header("Content-type: text/xml");
$txt="http://www.haneefputtur/xyx/138778535913.jpg";
$image=imagecreatefromjpeg($txt);

imagejpeg($image);

imagedestroy($image);

?>


If you wish to make it dynamic then store the image data in a mysql database.

Then select the image randomly or by sending query parameter so that you will get dynamic images.

 

Hereis the sample codes to get and display data from mysql database

 

<?php

$servername = “localhost”;

$username = “xxxxxxx”;

$password = “xxxx”;

$dbname = “haneee_2015”;

 

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn->connect_error) {

die(“Connection failed: ” . $conn->connect_error);

}

 

$sql = “SELECT img_name FROM hanee_2015.tbl_banners WHERE active=1 AND img_name LIKE ‘%.jpg%’ LIMIT “.$_GET[“img”].”, 1;”;

$result = $conn->query($sql);

 

 

if ($result->num_rows > 0) {

// output data of each row

while($row = $result->fetch_assoc()) {

$txt=”http://www.haneefputtur.com/test/uploads/” . $row[“img_name”]. ” <br>”;

 

}

} else {

 

$txt=”http://www.haneefputtur.com/test/uploads/138778535913.jpg”;

}

$conn->close();

?>

<?php

header(“Content-type: text/xml”);

$image=imagecreatefromjpeg($txt);

imagejpeg($image);

imagedestroy($image);

?>

 

This is a sample script.

You can call this image service using following test code

 

<html>

<body>

<img src="www.haneefputtur.com/test.php?img=1" />

</body>

</html>

 

 

Using this you can develop further.

For any help please leave your question.