Comments (6)
Try calling gc_collect_cycles
after unset($pdf)
to see if that helps.
from pdf-to-image.
Are you running the queue as a daemon?
from pdf-to-image.
Yes but I'm freeing the PDF object Variable from memory in loop. here is my code you can see or i can give you the demo if you want.
`
use Spatie\PdfToImage\Pdf;
use Intervention\Image\ImageManager as Image;
use App\Helpers\Utility;
public function handle()
{
echo Utility::bytesToHuman(memory_get_usage(true)) . " Job Started Object will create Now" . PHP_EOL;
$client = new Client(env('DROPBOX_ACCESS_TOKEN', config('dropbox.access_token')), env('DROPBOX_APP_SECRET', config('dropbox.app_secret')));
$adapter = new DropboxAdapter($client);
$filesystem = new Filesystem($adapter);
$Image = new Image();
echo Utility::bytesToHuman(memory_get_usage(true)) . " All Objects are creating except PDF library Image " . PHP_EOL;
Dropbox::where('is_process', 0)->where('type', 'file')->chunk(200, function ($dropboxArr) use ($filesystem, $Image) {
;
echo Utility::bytesToHuman(memory_get_usage(true)) . " Dropbox Model Chunk Query started " . PHP_EOL;
foreach ($dropboxArr as $row) {
/**
* Art Creation Process
*
*/
echo Utility::bytesToHuman(memory_get_usage(true)) . " First Loop started with file path " . $row->path . " " . PHP_EOL;
$art = Art::where('folder', $row->folder)->get()->first();
if (empty($art)) {
$maxCode = (Art::max('code') + 1);
$art = [
'title' => $row->folder,
'code' => $maxCode,
'folder' => $row->folder
];
Art::create($art);
}
echo Utility::bytesToHuman(memory_get_usage(true)) . " Art First Query process in loop " . PHP_EOL;
/**
* Print Checking & Create Process
*
*/
$print = Prnt::select('id', 'title', 'code')->where('title', trim($row->filename))->get()->first();
echo Utility::bytesToHuman(memory_get_usage(true)) . " Print 2nd Query process in loop " . PHP_EOL;
if (empty($print)) {
$maxCode = (Prnt::max('code') + 1);
/**
* Link Shared Process
*
*/
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.dropboxapi.com/2/sharing/create_shared_link",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode(array('path' => "/" . $row->path)),
CURLOPT_HTTPHEADER => array(
"authorization: Bearer " . env('DROPBOX_ACCESS_TOKEN', config('dropbox.access_token')),
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
} else {
$shared_link = json_decode($response);
}
echo Utility::bytesToHuman(memory_get_usage(true)) . " Dropbox shared link generation process in loop " . PHP_EOL;
/**
* Image Creation Process
*
*/
$fileExt = $row->extension;
$file = $filesystem->read(strtolower($row->path));
if (!empty($file)) {
echo Utility::bytesToHuman(memory_get_usage(true)) . " Dropbox file read process in loop " . PHP_EOL;
Storage::put('sync.' . $fileExt, $file);
$filePath = storage_path('app/sync.' . $fileExt);
$pdf = new Pdf($filePath);
echo Utility::bytesToHuman(memory_get_usage(true)) . " PDF object created in loop " . PHP_EOL;
$savePath = public_path('sync-mblob.jpg');
$pdf->saveImage($savePath);
$Image->make(public_path('sync-mblob.jpg'))->resize(150, 150)->save(public_path('sync-blob.jpg'));
/**
* Print Creation Process
*
*/
$print = [
'title' => trim($row->filename),
'code' => $maxCode,
'sample' => file_get_contents(public_path('sync-mblob.jpg')),
'thumbnail' => file_get_contents(public_path('sync-blob.jpg')),
'preview_url' => @$shared_link->url
];
echo Utility::bytesToHuman(memory_get_usage(true)) . " File get content method for both sample and thumb process in loop " . PHP_EOL;
$print = Prnt::create($print);
echo Utility::bytesToHuman(memory_get_usage(true)) . " Prnt record insert process in loop " . PHP_EOL;
$art = Art::where('folder', $row->folder)->get()->first();
echo Utility::bytesToHuman(memory_get_usage(true)) . " Art condition check process in loop " . PHP_EOL;
$art->prints()->attach([$print->id]);
Dropbox::where('id', $row->id)->update(['is_process' => 1]);
unset($pdf); //Removing the PDF Object to clear the memory consumption issue.
echo Utility::bytesToHuman(memory_get_usage(true)) . " PDF Object unset in loop to clear memory" . PHP_EOL;
} else {
echo Utility::bytesToHuman(memory_get_usage(true)) . " file was empty moving to next file " . PHP_EOL;
}
}
}
});
}
`
Note : I can provide you the demo if you want. below is your library code
`
$pdf = new Pdf($filePath);
echo Utility::bytesToHuman(memory_get_usage(true)) . " PDF object created in loop " . PHP_EOL;
$savePath = public_path('sync-mblob.jpg');
$pdf->saveImage($savePath);`
Thanks
Adil
from pdf-to-image.
Hi,
Ok I'll try this in my code after unset($pdf), I found another problem , there is difference between PDF image and converted image, is it possible, to convert the pdf image exactly same as image colours.
One more thing, I'm thinking the Linux CLI conversion is faster then php conversion do you have cli command to convert pdf to image.
Please Let me know about this.
Thanks
Adil
from pdf-to-image.
If you investigate this issue further, let me know your findings.
Currently we do not have an issue with the speed or image colours in our projects.
Using (and requiring) a CLI tool to perform the conversion would be a breaking change. So a PR would probably get rejected.
from pdf-to-image.
I investigate it properly and I found an issue some of the PDF files eating all the system memory and system automatically kills it and restart it, this is only happens with some PDF files we have in Dropbox, However If you want any of these let me know I will send you but for now I'm sending you one which I tried to figure out but got no success yet, You can try at your end to convert the file into image with same colours, then maybe you know why it's eating all the memory and hangs the server and system and why colours are different from original one.
One more thing I tried to upload this with convert in cli it's converted it properly.
Thanks
Adil
from pdf-to-image.
Related Issues (20)
- Nice script to create images from PDFs cover page (generally speaking) HOT 1
- Image width and height HOT 3
- Solution for worst case scenario HOT 3
- Multiple pages overlapped into one image when pdf is loaded from url HOT 4
- PHP 8 compatibility HOT 2
- Call to undefined method Spatie\PdfToImage\Pdf::setCompressionQuality() HOT 5
- Support for PHP 8.1 HOT 4
- PDFDelegateFailed `The system cannot find the file specified. ' @ error/pdf.c/ReadPDFImage/794 http://localhost:8000
- Spatie\PdfToImage\Exceptions\PdfDoesNotExist HOT 1
- PDF with Annotations? HOT 1
- "Pdf::setCompressionQuality()" HOT 3
- Image has a black background color HOT 4
- getNumberOfPages returns wrong number HOT 3
- Image size (width and height) issue HOT 2
- Support for php 8.x HOT 2
- After converting, the file does not open anymore. Message: Something went wrong. HOT 1
- imagick extintion dose now work HOT 7
- FailedToExecuteCommand when trying to ping PDF file HOT 5
- Webp support HOT 2
- Tag new release HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdf-to-image.