ApiController.php
3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers;
use App\pdfModel;
use URL;
use Storage;
use Response;
use File;
Use PDF;
use Illuminate\Support\Facades\Input;
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Facade;
use League\Flysystem\Filesystem;
use Curl\Curl;
use Imagick;
class ApiController extends Controller
{
//Takes json data and passes it to model and grabs related files.
public function insert($json)
{
$json = '{"pdf":[{"name":"SISKINDS_test file","folder":"SISKINDS_test","pdfLocation":"https://www.polyu.edu.hk/iaee/files/pdf-sample.pdf"}],"changes":[{"label":"none","locationUp":"400","locationRight":90,"pages":"1","content":"LOGO_text_black.jpg","z-index":null,"idstylesPDF":1,"order":"2","style":null,"idchange_typePDF":2,"change_type":"2","fileLocation":"http://www.arielpremium.com/images/vsample_images/LOGO_text_black.jpg"},{"label":"text style","locationUp":"60","locationRight":290,"pages":"1","content":"519.660.2121 siskinds.com\/change","z-index":null,"idstylesPDF":2,"order":"1","style":"a:3:{s:11:\"font-family\";s:11:\"TradeGothic\";s:9:\"font-size\";s:2:\"14\";s:10:\"font-color\";s:14:\"cmyk 0 0 0.5 0\";}","idchange_typePDF":1,"change_type":"1"}]}';
$apiCallId = new pdfModel();
$apiCallId = $apiCallId->addApiCall('1',$json);
//$apiCallId = "3";
$pdfId = new pdfModel();
$pdfId = $pdfId->addPdf($apiCallId, $json);
$json = json_decode($json);
$storagePath = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix();
$folder = str_replace(' ', '-', $json->pdf[0]->label); // Replaces all spaces with hyphens.
$folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder);
if(!is_dir($storagePath . $folder . '/')){
mkdir($storagePath . $folder . '/');
}
if (isset($json->pdf[0]->pdfLocation)) {
$pdfLocation = $json->pdf[0]->pdfLocation;
$file = explode('/', $pdfLocation);
$curl = new Curl();
$curl->download($pdfLocation, $storagePath . $folder . '/' . end($file));
$curl->close();
$im = new Imagick();
$im->setResolution(300, 300); //set the resolution of the resulting jpg
$im->readImage($storagePath . $folder . '/' . end($file)); //[0] for the first page
$im->setImageFormat('jpg');
$fileName = end($file);
$fileName = explode('.', $fileName);
$im->writeImage($storagePath . $folder . '/' . $fileName[0].'.jpg');
}
foreach ($json->changes as $change) {
if (isset($change->fileLocation)) {
$fileLocation = $change->fileLocation;
$file = explode('/', $fileLocation);
$curl = new Curl();
$curl->download($fileLocation, $storagePath . $folder . '/' . end($file));
$curl->close();
}
}
}
public function getList($json)
{
$rows = new pdfModel();
$rows = $rows->getList($json)->get();
$rows = json_encode($rows);
var_dump($rows);
}
public function getPdf($json)
{
$rows = new pdfModel();
$rows = $rows->getpdf($json)->get();
$rows = json_encode($rows);
var_dump($rows);
}
}