Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdf2pic

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdf2pic - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

2

dist/index.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("gm"),e=require("path"),i=require("fs-extra"),s=require("stream");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=r(t),a=r(e),o=r(i);const h={quality:0,format:"png",width:768,height:512,density:72,savePath:"./",saveFilename:"untitled",compression:"jpeg"};class u{constructor(){this.quality=0,this.format="png",this.width=768,this.height=512,this.density=72,this.savePath="./",this.saveFilename="untitled",this.compression="jpeg",this.gm=n.default}generateValidFilename(t){return"number"==typeof t?`${this.savePath}/${this.saveFilename}.${t+1}.${this.format}`:`${this.savePath}/${this.saveFilename}.${this.format}`}gmBaseCommand(t,e){return this.gm(t,e).density(this.density,this.density).resize(this.width,this.height,"!").quality(this.quality).compress(this.compression)}toBase64(t,e){const i=`${t.path}[${e}]`;return new Promise((s,r)=>{this.gmBaseCommand(t,i).stream(this.format,(t,i)=>{let n="";if(t)return r(t);i.on("data",t=>{n+=t.toString("binary")}).on("end",()=>{const t=Buffer.from(n,"binary").toString("base64");return s({base64:t,size:`${this.width}x${this.height}`,page:e+1})})})})}writeImage(t,e){const i=this.generateValidFilename(e),s=`${t.path}[${e}]`;return new Promise((r,n)=>{this.gmBaseCommand(t,s).write(i,t=>t?n(t):r({name:a.default.basename(i),size:o.default.statSync(i).size/1e3,path:i,page:e+1}))})}identify(t,e){const i=this.gm(t);return new Promise((t,s)=>{e?i.identify(e,(e,i)=>e?s(e):t(i.replace(/^[\w\W]*?1/,"1"))):i.identify((e,i)=>e?s(e):t(i))})}setQuality(t){return this.quality=t,this}setFormat(t){return this.format=t,this}setSize(t,e){return this.width=t,this.height=e||t,this}setDensity(t){return this.density=t,this}setSavePath(t){return this.savePath=t,this}setSaveFilename(t){return this.saveFilename=t,this}setCompression(t){return this.compression=t,this}setGMClass(t){return"boolean"==typeof t?(this.gm.subClass({imageMagick:t}),this):"imagemagick"===t.toLocaleLowerCase()?(this.gm.subClass({imageMagick:!0}),this):(this.gm.subClass({appPath:t}),this)}getOptions(){return{quality:this.quality,format:this.format,width:this.width,height:this.height,density:this.density,savePath:this.savePath,saveFilename:this.saveFilename,compression:this.compression}}}function m(t){return new s.Readable({read(){this.push(t),this.push(null)}})}function f(t,e){if("buffer"===t)return m(e);if("path"===t)return i.createReadStream(e);if("base64"===t)return s=e,m(Buffer.from(s,"base64"));var s;throw new Error("Cannot recognize specified source")}function l(t,e,i,s){return new(i||(i=Promise))((function(r,n){function a(t){try{h(s.next(t))}catch(t){n(t)}}function o(t){try{h(s.throw(t))}catch(t){n(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,o)}h((s=s.apply(t,e||[])).next())}))}function c(t,e,i,s=1,r=!1){return l(this,void 0,void 0,(function*(){if(-1!==s&&s<1)throw new Error("Page number should be more than or equal 1");const n=f(e,i),a=f(e,i),o=Array.isArray(s)?s:[s];return(s=-1===s?yield function(t,e){return l(this,void 0,void 0,(function*(){return(yield t.identify(e,"%p ")).split(" ").map(t=>parseInt(t,10))}))}(t,a):o).map(e=>{if(s<1)throw new Error("Page number should be more than or equal 1");return r?t.toBase64(n,e-1):t.writeImage(n,e-1)})}))}function d(t,e,i=h){const s=new u;i=Object.assign(Object.assign({},h),i);const r=(i=1,r=!1)=>{if(i<1)throw new Error("Page number should be more than or equal 1");const n=f(t,e);return r?s.toBase64(n,i-1):s.writeImage(n,i-1)};return r.bulk=(i,r=!1)=>c(s,t,e,i,r),r.setOptions=()=>function(t,e){return void t.setQuality(e.quality).setFormat(e.format).setSize(e.width,e.height).setDensity(e.density).setSavePath(e.savePath).setSaveFilename(e.saveFilename).setCompression(e.compression)}(s,i),r.setGMClass=t=>{s.setGMClass(t)},r.setOptions(),r}exports.fromBase64=function(t,e=h){return d("base64",t,e)},exports.fromBuffer=function(t,e=h){return d("buffer",t,e)},exports.fromPath=function(t,e=h){return d("path",t,e)};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("gm"),e=require("path"),i=require("fs-extra"),s=require("stream");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=r(t),a=r(e),h=r(i);const o={quality:0,format:"png",width:768,height:512,density:72,savePath:"./",saveFilename:"untitled",compression:"jpeg"};class u{constructor(){this.quality=0,this.format="png",this.width=768,this.height=512,this.density=72,this.savePath="./",this.saveFilename="untitled",this.compression="jpeg",this.gm=n.default}generateValidFilename(t){return"number"==typeof t?`${this.savePath}/${this.saveFilename}.${t+1}.${this.format}`:`${this.savePath}/${this.saveFilename}.${this.format}`}gmBaseCommand(t,e){return this.gm(t,e).density(this.density,this.density).resize(this.width,this.height,"!").quality(this.quality).compress(this.compression)}toBase64(t,e){const i=`${t.path}[${e}]`;return new Promise((s,r)=>{this.gmBaseCommand(t,i).stream(this.format,(t,i)=>{let n="";if(t)return r(t);i.on("data",t=>{n+=t.toString("binary")}).on("end",()=>{const t=Buffer.from(n,"binary").toString("base64");return s({base64:t,size:`${this.width}x${this.height}`,page:e+1})})})})}writeImage(t,e){const i=this.generateValidFilename(e),s=`${t.path}[${e}]`;return new Promise((r,n)=>{this.gmBaseCommand(t,s).write(i,t=>t?n(t):r({name:a.default.basename(i),size:`${this.width}x${this.height}`,fileSize:h.default.statSync(i).size/1e3,path:i,page:e+1}))})}identify(t,e){const i=this.gm(t);return new Promise((t,s)=>{e?i.identify(e,(e,i)=>e?s(e):t(i.replace(/^[\w\W]*?1/,"1"))):i.identify((e,i)=>e?s(e):t(i))})}setQuality(t){return this.quality=t,this}setFormat(t){return this.format=t,this}setSize(t,e){return this.width=t,this.height=e||t,this}setDensity(t){return this.density=t,this}setSavePath(t){return this.savePath=t,this}setSaveFilename(t){return this.saveFilename=t,this}setCompression(t){return this.compression=t,this}setGMClass(t){return"boolean"==typeof t?(this.gm.subClass({imageMagick:t}),this):"imagemagick"===t.toLocaleLowerCase()?(this.gm.subClass({imageMagick:!0}),this):(this.gm.subClass({appPath:t}),this)}getOptions(){return{quality:this.quality,format:this.format,width:this.width,height:this.height,density:this.density,savePath:this.savePath,saveFilename:this.saveFilename,compression:this.compression}}}function m(t){return new s.Readable({read(){this.push(t),this.push(null)}})}function f(t,e){if("buffer"===t)return m(e);if("path"===t)return i.createReadStream(e);if("base64"===t)return s=e,m(Buffer.from(s,"base64"));var s;throw new Error("Cannot recognize specified source")}function l(t,e,i,s){return new(i||(i=Promise))((function(r,n){function a(t){try{o(s.next(t))}catch(t){n(t)}}function h(t){try{o(s.throw(t))}catch(t){n(t)}}function o(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,h)}o((s=s.apply(t,e||[])).next())}))}function c(t,e,i,s=1,r=!1){return l(this,void 0,void 0,(function*(){if(-1!==s&&s<1)throw new Error("Page number should be more than or equal 1");const n=f(e,i),a=f(e,i),h=Array.isArray(s)?s:[s],o=(s=-1===s?yield function(t,e){return l(this,void 0,void 0,(function*(){return(yield t.identify(e,"%p ")).split(" ").map(t=>parseInt(t,10))}))}(t,a):h).map(e=>{if(s<1)throw new Error("Page number should be more than or equal 1");return r?t.toBase64(n,e-1):t.writeImage(n,e-1)});return Promise.all(o)}))}function d(t,e,i=o){const s=new u;i=Object.assign(Object.assign({},o),i);const r=(i=1,r=!1)=>{if(i<1)throw new Error("Page number should be more than or equal 1");const n=f(t,e);return r?s.toBase64(n,i-1):s.writeImage(n,i-1)};return r.bulk=(i,r=!1)=>c(s,t,e,i,r),r.setOptions=()=>function(t,e){return void t.setQuality(e.quality).setFormat(e.format).setSize(e.width,e.height).setDensity(e.density).setSavePath(e.savePath).setSaveFilename(e.saveFilename).setCompression(e.compression)}(s,i),r.setGMClass=t=>{s.setGMClass(t)},r.setOptions(),r}exports.fromBase64=function(t,e=o){return d("base64",t,e)},exports.fromBuffer=function(t,e=o){return d("buffer",t,e)},exports.fromPath=function(t,e=o){return d("path",t,e)};
import { WriteImageResponse } from "@module/types/writeImageResponse";
import { ToBase64Response } from "@module/types/toBase64Response";
export declare type Convert = {
bulk?: (pages?: number | number[], toBase64?: boolean) => Promise<(Promise<WriteImageResponse> | Promise<ToBase64Response>)[]>;
bulk?: (pages?: number | number[], toBase64?: boolean) => Promise<WriteImageResponse[] | ToBase64Response[]>;
setOptions?: () => void;

@@ -6,0 +6,0 @@ setGMClass?: (gmClass: string | boolean) => void;

export declare type WriteImageResponse = {
name?: string;
size?: number;
size?: string;
fileSize?: number;
path?: string;
page?: number;
};

@@ -5,2 +5,2 @@ /// <reference types="node" />

import { ToBase64Response } from "@module/types/toBase64Response";
export declare function bulkConvert(gm: Graphics, source: string, filePath: string | Buffer, pageNumber?: number | number[], toBase64?: boolean): Promise<(Promise<WriteImageResponse> | Promise<ToBase64Response>)[]>;
export declare function bulkConvert(gm: Graphics, source: string, filePath: string | Buffer, pageNumber?: number | number[], toBase64?: boolean): Promise<WriteImageResponse[] | ToBase64Response[]>;
{
"name": "pdf2pic",
"version": "2.0.0",
"version": "2.1.0",
"description": "A utility for converting pdf to image and base64 format.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc