The JPG (or JPEG) format is with no doubt the most favored format used to transfer images on the web. Nevertheless, there are several benefits in using PDF pictures compared to JPG ones. For one, though the JPG format is a raster form with lossy reduction, PDF is a structured format that includes both vectors with raster graphics.
This indicates that while the quality of the print of JPG photos relies on their pixel sizes, PDF images can print out precisely what you see on the net. Again, the PDF format backs text search within PDF with OCR and can include richer metadata rather than JPG format.
If you would want to convert a JPG format file to PDF format on a system like Linux/Ubuntu, you can employ some of the following ways that work well on any of the systems.
1. Convert JPEG file to PDF form employing ImageMagick
The converting command can not be a default Linux system, and this doesn’t come with most allocations. There’s a fair chance that you’ll require to install it. Convert arrives from ImageMagick, a prevalent image manipulation way used by many of applications. Start by installing the same on your system.
Foremost, install ImageMagick on the Linux/Ubuntu.
Among the utilities included in the ImageMagick packet, a utility named convert can transform from JPG to PDF. This convert command shall scale input picture such that this will equip either page width or height. You can then run convert as follows.
$ convert input.jpg output.pdf
If you like to convert numerous JPG images to one PDF file with numerous pages:
$ convert input1.jpg input2.jpg input3.jpg output.pdf
Or:
$ convert *.jpg output.pdf
Then per JPG file will be transformed into one page of the multi PDF file.
To determine the size of the page (i.e., canvas), you can utilize -the page option of the convert. If the page size is larger than the image size, the picture will be set on the lower-left side of a page.
How to Resize the Image
If you are moving to include a picture on a webpage and want to be a picture of a certain size then could employ some CSS. It is really better though to image upload as the proper size in the foremost place and then insert into the page. This is just one instance of why you may like to resize an image.
To resize the image use the ensuing command
convert imagename.jpg -resize dimensions newimagename.jpg
How to Adjust the Size for the file of Image
There is a digit of ways to modify the file size of an image.
- Adjust the aspect ratio (make it smaller)
- Modify the file format
- Modify the compression quality
Downsizing the size of the picture will make the size smaller. In expansion, employing a file format that contains compression like JPG shall enable to reduce the file size.
Finally modifying the image quality shall make the file size look smaller. The quality is thus determined as a percentage. The more down the percentage the less the output but apparently the last output quality is something that might not be as good.
2. Convert JPEG image format of file to PDF format file using Ghostscript tool-
First, just need to install Ghostscript on your Linux/Ubuntu.
Then, go running the gs command to transform a JPG image to PDF format as mentioned below-
To convert numerous JPG images (e.g., input1.jpg, input2.jpg, input3.jpg) to one PDF file (with numerous pages)
. Automate JPG conversion to PDF
If you need to automate JPG file to pdf format conversion, then can add the overhead command in a script as indicated below. Create an empty shell script.
$ sudo vi jpg_to_pdf.sh
Add the subsequent lines to it.
#!/bin/sh
$ mogrify -format pdf /home/ubuntu/*.jpg
Save and shut the file. Assemble it executable with the subsequent command.
$ sudo chmod +x jpg_to_pdf.sh
Run it with the next command.
$ ./jpg_to_pdf.sh
You may actually create a cronjob to execute the above writing very easily. Just need to open the crontab using the following command.
$ crontab -e
include the following line to it.
0 10 * * * sudo ./jpg_to_pdf >/dev/null 2>&1
Save and shut the file. This shall run your overhead shell script.
Thus, In this piece, we have discovered how to transform JPG to PDF using various ways. You can even use it to transform PNG and other picture types to PDF. We even learned how to transform multiple formats at one time, and even how to automate JPG conversion to PDF with the help of shell scripts and cronjobs.
Please cite, you can even call convert and modify from and within your preferred application. For instance, if you are having Python for processing backend, then can call the overhead commands employing subprocess.call or subprocess.popen commands.