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

@@ -149,14 +149,28 @@ function get_images($document_reference){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $drawings_url);
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
$response = curl_exec($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

@@ -140,10 +140,13 @@ include '../ops_api.php'
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
endif;

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

@@ -127,10 +127,13 @@ $publication_details = get_publication_details($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
endif;

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

@@ -31,10 +31,13 @@ $random_doc_refs = ten_random_doc_refs($core);
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
endforeach;

Loading…
Cancel
Save