Browse Source

using ImageMagick to convert TIFFs from API to PNGs for display

main
Simon Bowie 2 years ago
parent
commit
123b307fee
4 changed files with 35 additions and 12 deletions
  1. +17
    -3
      site/ops_api.php
  2. +6
    -3
      site/public/id_search.php
  3. +6
    -3
      site/public/random.php
  4. +6
    -3
      site/public/random_images.php

+ 17
- 3
site/ops_api.php View File

$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $drawings_url); curl_setopt($ch, CURLOPT_URL, $drawings_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token","Accept: application/pdf"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token","Accept: application/tiff"));


// Give back curl result // Give back curl result
$response = curl_exec($ch); $response = curl_exec($ch);
curl_close($ch); curl_close($ch);


// Return the PDF response
return $response;
// Create Imagick object
$image = new Imagick();

// Convert image into Imagick
$image->readimageblob($response);

// Convert image to png
$image->setImageFormat("png");

// Add a subtle border
$color=new ImagickPixel();
$color->setColor("rgb(220,220,220)");
$image->borderImage($color,1,1);

// Return the Imagick object
return $image;


} }



+ 6
- 3
site/public/id_search.php View File

if (check_for_images($result['doc_ref'])): if (check_for_images($result['doc_ref'])):
?> ?>


<iframe src="./ops_image.php?doc_ref=<?php echo $result['doc_ref'] ?>#view=fitH" height="780px" width="100%">
</iframe>
<?php
$image = get_images($result["doc_ref"]);
?>


<br><br>
<?php
echo '<img class="img-fluid" src="data:image/jpg;base64,'.base64_encode($image->getImageBlob()).'" alt="Drawing of patent" />';
?>


<?php <?php
endif; endif;

+ 6
- 3
site/public/random.php View File

if (check_for_images($random_record['doc_ref'])): if (check_for_images($random_record['doc_ref'])):
?> ?>


<iframe src="./ops_image.php?doc_ref=<?php echo $random_record['doc_ref'] ?>#view=fitH" height="780px" width="100%">
</iframe>
<?php
$image = get_images($random_record["doc_ref"]);
?>


<br><br>
<?php
echo '<img class="img-fluid" src="data:image/jpg;base64,'.base64_encode($image->getImageBlob()).'" alt="Drawing of patent" />';
?>


<?php <?php
endif; endif;

+ 6
- 3
site/public/random_images.php View File

foreach($random_doc_refs as $doc_ref): foreach($random_doc_refs as $doc_ref):
?> ?>


<iframe src="./ops_image.php?doc_ref=<?php echo $doc_ref ?>" width="100%" height="500px">
</iframe>
<?php
$image = get_images($doc_ref);
?>


<br><br>
<?php
echo '<img class="img-fluid" src="data:image/jpg;base64,'.base64_encode($image->getImageBlob()).'" alt="Drawing of patent" />';
?>


<?php <?php
endforeach; endforeach;

Loading…
Cancel
Save