Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Density Option Support #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,17 @@ public function quality(int $quality): self

return $this;
}

/**
* @see http://imagemagick.org/script/command-line-options.php#density
*/
public function density(int $density): self
{
$densityAry = [];
$densityAry[] = '-density';
$densityAry[] = (string) $density;
array_splice($this->command,2,0,$densityAry); //density option only works when it's on second place in command (tested for pdf to image)
Copy link
Member

@Pierstoval Pierstoval Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Density is not supposed to be placed "second place in command", but "before any vector source is specified".

If you use ImageMagick to manipulate multiple files or intermediary files, you should be able to specify the density for all files.

You say you "tested for pdf to image", but if you test "image to pdf", you'll realize that the density option must be put before the pdf filename, like this for instance: convert my-file.jpg -density 300 my-file.pdf.

Another case is units. By default, density is in dpi (dots per inch), but you can use the -units option to switch to dots per centimeters, but it has to be specified before the -density option. Your code proposal doesn't allow that.

Also, the density option must respect its specified format: {width} | {width}x{height}.
You can add a small function to the Reference class that will validate these rules.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to read Reference classes but didn't get so much idea how i will gonna add these options but i'll try.

return $this;
}
/**
* @param string|Geometry $page
*
Expand Down