"; // get the first 4 digits $sFirstFour = substr($MLS_num,0,4); $sRestFour = substr($MLS_num,4); $sTempFilePath = "/home/bostonc/public_html/images/mls/raw/$sFirstFour"; $sTempFilePath .= "$sRestFour"; $sTempFilePath .= "_$sOrder.jpg"; //echo "temp path $sTempFilePath"; $fileTemp = fopen($sTempFilePath, 'w'); // echo "temp file = $fileTemp "; /* if ($fileTemp) { echo "file opened"; } */ //echo "connect $conn, $fileTemp, $strRemote_file"; //echo "now in photo/$sFirstTwo/$sSecondthree"; if (ftp_fget($conn, $fileTemp, $strRemote_file, FTP_BINARY)) { $bDLed = 1; } fclose($fileTemp); // Now read back in the temp file. //$sData = file_get_contents($sTempFilePath); // echo strlen($sData); $sSourcePath = $sTempFilePath; } } } } } if ($bDLed < 1) { $image = imagecreatefromgif("/home/bostonc/public_html/images/noPhoto3.gif"); header('Content-type: image/jpeg'); imagejpeg($image); // output the stream directly //echo $sFilePath; return "0"; } //**************** /* if ($sData == FALSE) { echo "Failed to get image from mls"; return "http://www.boston-condo.com/images/mls/no_photo.bmp"; } */ //echo "$sData"; //echo "$filename"; // Creates the directory if it doesn't exist. PrepareDirectory($MLS_num); if ($bThumb) { // Make the full sized image. make_image_from_source($sSourcePath, $filename, 128); } else { // Make the full sized image. make_image_from_source($sSourcePath, $filename, 384); //$hFile = fopen($filename, "w"); //$nBytesWriten = fwrite($hFile, $sData); //fclose($hFile); //$nBytesWriten = file_put_contents($filename, $sData); //echo "$nBytesWriten"; //if ($nBytesWriten < 2) //{ // echo "Failed to write image to local cache"; // return "http://www.boston-condo.com/images/mls/no_photo.bmp"; } } unlink($sSourcePath); // get the first 4 digits $sFirstFour = substr($MLS_num,0,4); $sRestFour = substr($MLS_num,4); //echo("yes"); $sFilePath = "/home/bostonc/public_html/images/mls/$sFirstFour"; $sFilePath .= "/$sRestFour"; $sFilePath .= "_$sOrder"; if ($bThumb) { $sFilePath .= "_th"; } $sFilePath .= ".jpg"; //header("Content-type: image/jpeg"); //header('Content-transfer-encoding: binary'); //header('Content-length: '.filesize($sFilePath)); //readfile($sFilePath); //header("Location: $sFilePath"); //echo $sFilePath; // $image = ImageCreateFromJPEG($sFilePath); header('Content-type: image/jpeg'); // imagejpeg($image); // output the stream directly // optional way to output the stream without having to use GD readfile($sFilePath); //echo $sFilePath; return $sFilePath; } // **************************** function IsCacheNewer($pfn,$w,$h,$bc,$bResize) { $strCacheName = $pfn; $strCacheName .= $w; $strCacheName .= $h; $strCacheName .= $bc; $strCacheName .= $bResize; // echo "$strCacheName"; $strImgCachePath = "/home/bostonc/public_html/c9234570/"; $strImgCachePath .= $strCacheName; $strImgRawPath = '/home/bostonc/public_html/images/listing_photos/'; // Get the source path. $strImgRawPath .= $pfn; //echo "P1"; if (file_exists($strImgCachePath)) { //echo "P2"; if (file_exists($strImgRawPath)) { //echo "P3"; $nCacheTime = filemtime($strImgCachePath); $nRawTime = filemtime($strImgRawPath); // Compare the times. Is cache bigger? if ($nRawTime < $nCacheTime) { //echo "P4"; return TRUE; } } else { return TRUE; } } return FALSE; } // **************************** function ServeCache($pfn,$w,$h,$bc,$bResize) { $strCacheName = $pfn; $strCacheName .= $w; $strCacheName .= $h; $strCacheName .= $bc; $strCacheName .= $bResize; $strImgCachePath = "/home/bostonc/public_html/c9234570/"; $strImgCachePath .= $strCacheName; //echo "$strImgCachePath"; if (file_exists($strImgCachePath)) { //echo "file found"; header('Content-type: image/jpeg'); readfile($strImgCachePath); } } // *************************** function getInHousePhoto($pfn,$w,$h,$bc,$bResize) { //echo "$pfn,$w,$bc"; $InHousePhotoPath = '/home/bostonc/public_html/images/listing_photos/'; // Max image width $nMaxImageDim = 640; // Get the source path. $sourcefile = $InHousePhotoPath . $pfn; // If its a thubmnail just fling it. if ($w < 101) { header('Content-type: image/jpeg'); readfile($sourcefile); } else { $fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3)); switch($fileType) { case('gif'): $sourcefile_id = imagecreatefromgif($sourcefile); break; case('png'): $sourcefile_id = imagecreatefrompng($sourcefile); break; default: $sourcefile_id = imagecreatefromjpeg($sourcefile); } //Get the sizes of both pix $sourcefile_width=imageSX($sourcefile_id); $sourcefile_height=imageSY($sourcefile_id); // If a gif, we have to upsample it to a truecolor image if($fileType == 'gif') { // create an empty truecolor container $tempimage = imagecreatetruecolor($sourcefile_width,$sourcefile_height); // copy the 8-bit gif into the truecolor image imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height); // copy the source_id int $sourcefile_id = $tempimage; } // only for big images if ($sourcefile_width > 175) { // Get the logo path $watermarkfile = "/home/bostonc/public_html/images2/" . $bc . "2.png"; // Get the watermark path $WebAddrmarkfile = "/home/bostonc/public_html/images2/" . $bc . ".png"; //Get the resource id of the web address image. $Webaddrmarkfile_id = imagecreatefrompng($WebAddrmarkfile); //Get the resource id of the watermark. $watermarkfile_id = imagecreatefrompng($watermarkfile); $watermarkfile_width=imageSX($watermarkfile_id); $watermarkfile_height=imageSY($watermarkfile_id); $Webaddr_width=imageSX($Webaddrmarkfile_id); $Webaddr_height=imageSY($Webaddrmarkfile_id); //echo "$watermarkfile_width"; // If the photo is turned like a tower we need to pad it so it doesn't get distorted. //if (FALSE) what about no_pad if ($sourcefile_width + 50 < $sourcefile_height) { if (($sourcefile_height > ($nMaxImageDim * 0.75)) && ($bResize !== TRUE)) { $bResize = TRUE; $nScale = 1.0; $h = $nMaxImageDim * 0.75; // $nScale = ($nMaxImageDim / $sourcefile_height); $w = $nMaxImageDim; } $NewW = $sourcefile_height * 1.3333333; $NewH = $sourcefile_height; $nScale = 1.0; if ($bResize ===TRUE) { $nScale = $h / $sourcefile_height; $NewW = $w; $NewH = $h; //$nScaleW = $NewW / $sourcefile_width; // $nScaleH = $NewH / $sourcefile_height; } $imgPadding = imagecreatetruecolor($NewW, $NewH); $white = imagecolorallocate($imgPadding, 210, 210, 215); imagefill($imgPadding, 0, 0, $white); $dest_x = 0; if ($bResize === TRUE) { $dest_x = ($NewW / 2 ) - (( $sourcefile_width * $nScale) / 2); imagecopyresampled($imgPadding, $sourcefile_id, $dest_x, 0, 0, 0,($sourcefile_width * $nScale), $NewH, $sourcefile_width, $sourcefile_height); } else { $dest_x = ($NewW / 2 ) - (( $sourcefile_width) / 2); imagecopy($imgPadding, $sourcefile_id, $dest_x, 0, 0, 0,$sourcefile_width, $sourcefile_height); } // destroy the source imagedestroy($sourcefile_id); // recreate the image $sourcefile_id = imagecreatetruecolor($NewW, $NewH); imagecopy($sourcefile_id, $imgPadding, 0, 0, 0, 0,$NewW, $NewH); // destroy the source imagedestroy($imgPadding); // Do the watermarks. $dest_x = ( $NewW / 2 ) + (( $sourcefile_width * $nScale) / 2) - ( $Webaddr_width) - 5; $dest_y = ( $NewH ) - ( $Webaddr_height ) - 5; imagecopymerge($sourcefile_id, $Webaddrmarkfile_id, $dest_x, $dest_y, 0, 0,$Webaddr_width, $Webaddr_height,80); $dest_x = ( $NewW / 2 ) - ( $watermarkfile_width / 2 ); $dest_y = ( $NewH / 6) - ( $watermarkfile_height / 2) ; //$dest_x = 15; //$dest_y = 25; imagecopymerge($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0,$watermarkfile_width, $watermarkfile_height,7); } else { // If we want to resize it to fit better. if ($bResize === TRUE) { $imgTemp = imagecreatetruecolor($w, $h); imagecopyresampled($imgTemp, $sourcefile_id, 0, 0, 0, 0,$w, $h,$sourcefile_width, $sourcefile_height); // destroy the source imagedestroy($sourcefile_id); // recreate the image $sourcefile_id = imagecreatetruecolor($w, $h); imagecopy($sourcefile_id, $imgTemp, 0, 0, 0, 0,$w, $h); // destroy the source imagedestroy($imgTemp); $sourcefile_width = $w; $sourcefile_height = $h; } else if ($sourcefile_width > $nMaxImageDim) { $nScale = 1.0; $w = $nMaxImageDim; $nScale = ($nMaxImageDim / $sourcefile_width); $h = $nScale * $sourcefile_height; $imgTemp = imagecreatetruecolor($w, $h); imagecopyresampled($imgTemp, $sourcefile_id, 0, 0, 0, 0,$w, $h,$sourcefile_width, $sourcefile_height); // destroy the source imagedestroy($sourcefile_id); // recreate the image $sourcefile_id = imagecreatetruecolor($w, $h); imagecopy($sourcefile_id, $imgTemp, 0, 0, 0, 0,$w, $h); // destroy the source imagedestroy($imgTemp); $sourcefile_width = $w; $sourcefile_height = $h; } $dest_x = ( $sourcefile_width ) - ( $Webaddr_width) - 5; $dest_y = ( $sourcefile_height ) - ( $Webaddr_height ) - 5; imagecopymerge($sourcefile_id, $Webaddrmarkfile_id, $dest_x, $dest_y, 0, 0,$Webaddr_width, $Webaddr_height,80); //$dest_x = ( $sourcefile_width ) - ( $watermarkfile_width) ; //$dest_y = ( $sourcefile_height ) - ( $watermarkfile_height ); // write the string at the top left //imagestring($sourcefile_id, 3, $dest_x, $dest_y, "www.Boston-Condo.com", 16777215); $dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 ); $dest_y = ( $sourcefile_height / 6) - ( $watermarkfile_height / 2) ; //$dest_x = 15; //$dest_y = 25; imagecopymerge($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0,$watermarkfile_width, $watermarkfile_height,7); } imagedestroy($watermarkfile_id); imagedestroy($Webaddrmarkfile_id); } //Create a jpeg out of the modified picture header("Content-type: image/jpeg"); imagejpeg ($sourcefile_id); // record the cache $strCacheName = $pfn; $strCacheName .= $w; $strCacheName .= $h; $strCacheName .= $bc; $strCacheName .= $bResize; $strImgCachePath = "/home/bostonc/public_html/c9234570/"; $strImgCachePath .= $strCacheName; ob_start(); //header("Content-type: image/jpeg"); imagejpeg ($sourcefile_id); $image_data = ob_get_contents(); ob_end_clean(); if (strlen($image_data) > 5) { // open file $hCacheFile = fopen($strImgCachePath, 'w'); $nBytesWriten = fwrite($hCacheFile, $image_data); fclose($hCacheFile); } // header("Content-type: image/png"); // imagepng ($watermarkfile_id); imagedestroy($sourcefile_id); } } // *************************** error_reporting(1); $bTumbnail = FALSE; $bResize = FALSE; $bNoPadding = FALSE; $nTH = 0; $nResize = 0; $nW = 0; $nH = 0; $nN = 0; $pfn = ""; $bc = ""; $StrN = ""; $StrMLS = ""; $nMLS = 0; if(isset($_GET['th'])) { $StrTH = $_GET['th']; // Make it safe. $nTH = intval($StrTH); } if(isset($_GET['resize'])) { $StrResize = $_GET['resize']; // Make it safe. $nResize = intval($StrResize); } if(isset($_GET['w'])) { $StrW = $_GET['w']; // Make it safe. $nW = intval($StrW); } if(isset($_GET['h'])) { $StrH = $_GET['h']; // Make it safe. $nH = intval($StrH); } if(isset($_GET['n'])) { $StrN = $_GET['n']; // Make it safe. $nN = intval($StrN); $StrN = strval($nN); } if(isset($_GET['mls'])) { $StrMLS = $_GET['mls']; // Make it safe. $nMLS = intval($StrMLS); $StrMLS = strval($nMLS); } if(isset($_GET['pfn'])) { // !!! warning $pfn = $_GET['pfn']; } if(isset($_GET['bc'])) { $bc = $_GET['bc']; } if ($nTH === 1) { $bTumbnail = TRUE; } if ($nResize === 1) { $bResize = TRUE; } if ($nW === 64) { $bTumbnail = TRUE; } //echo "$mls,$n, $bTumbnail"; // if it is an MLS image if ($nMLS > 10000) { //echo "test"; $sImagePath = getphoto($StrMLS,$nN, $bTumbnail); } // else it is an inhouse listing. else { // if the width is ok and the "photo file name" is there if (($nW > 24) && ($nW < 801) && (strlen($pfn) > 2)) { if (!(($bc == "BC") || ($bc == "LB") || ($bc == "LBL") || ($bc == "BL"))) { $bc = "BC"; } // Check if the cached copy is newer than the raw one. if (($nW > 100) && (IsCacheNewer($pfn,$nW,$nH,$bc,$bResize)) ) { ServeCache($pfn,$nW,$nH,$bc,$bResize); } else { //echo "test"; $sImagePath = getInHousePhoto($pfn,$nW,$nH,$bc,$bResize); } } } //echo ""; ?>