Best way to reduce file size/resolution on upload?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Best way to reduce file size/resolution on upload?

Post by Bonzo »

Check my site there is loads of php stuff there.

Try:

Code: Select all

<?php 
echo "<pre>"; 
system("type convert");  
echo "</pre>"; 
?> 
OR
<?php 
echo "<pre>"; 
system('which convert',$path); print_r($path);  
echo "</pre>"; 
?> 
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Best way to reduce file size/resolution on upload?

Post by fmw42 »

which convert as above will tell you where IM is installed and what version to use.

using Bonzo's code, my command would look like

Code: Select all

<?php 
$array=array(); 
echo "<pre>"; 
exec("convert -define jpeg:size=300x300 inputimage -resize 300x300 -depth 8 -quality 75 -density 72 -units pixelsperinch resultimage 2>&1", $array);  
print_r($array);  
echo "</pre>"; 
?> 
The $array and print_r($array) will collect any errors and send them to the display. You will have to open the image separately as this only creates it and does not display it. However, Bonzo has code to do that and you should look over his site, if you want a pure PHP solution.

Note that in the code window above the convert command is really one long line and not split into two lines as the code window show it.
raindance
Posts: 20
Joined: 2010-10-24T11:17:34-07:00
Authentication code: 8675308

Re: Best way to reduce file size/resolution on upload?

Post by raindance »

Thanks to you both...will pass along....I really appreciate it!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Best way to reduce file size/resolution on upload?

Post by anthony »

See IM Examples... Thumbnails Which provides all the details on this and more.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
raindance
Posts: 20
Joined: 2010-10-24T11:17:34-07:00
Authentication code: 8675308

Re: Best way to reduce file size/resolution on upload?

Post by raindance »

He says he tried this:

<?php
$array=array();
echo "<pre>";
exec("convert -define jpeg:size=300x300 http://www.juicyhotels.com/images/manual_images/mia.jpg -resize 300x300 -depth 8 -quality 75 -density 72 -units 72 http://www.juicyhotels.com/images/manua ... s/mia2.jpg 2>&1", $array);
print_r($array);
echo "</pre>";
?>

And this was the result:

Array
(
[0] => sh: convert: command not found
)


Any idea?
raindance
Posts: 20
Joined: 2010-10-24T11:17:34-07:00
Authentication code: 8675308

Re: Best way to reduce file size/resolution on upload?

Post by raindance »

Does that mean we dont have IM installed correctly?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Best way to reduce file size/resolution on upload?

Post by Bonzo »

It might be or it might not - how about getting him to run the code I posted above. You may need to use the full path to convert in your code and this code will tell you what it is.

Code: Select all

<?php 
echo "<pre>"; 
system("type convert");  
echo "</pre>"; 
?> 
OR
<?php 
echo "<pre>"; 
system('which convert',$path); print_r($path);  
echo "</pre>"; 
?> 

raindance
Posts: 20
Joined: 2010-10-24T11:17:34-07:00
Authentication code: 8675308

Re: Best way to reduce file size/resolution on upload?

Post by raindance »

I think he thought he did...
Server company says its installed right...dev is working on it...sent him your code...thanks. He thinks maybe he got it done.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Best way to reduce file size/resolution on upload?

Post by fmw42 »

typical paths to convert are

/usr/local/bin/convert

or

/usr/bin/convert

You may have to use the correct one in your PHP exec command. But the which convert command should tell you where IM convert is located exactly if it is really installed.
raindance
Posts: 20
Joined: 2010-10-24T11:17:34-07:00
Authentication code: 8675308

Re: Best way to reduce file size/resolution on upload?

Post by raindance »

He got it :-)
Thanks everyone for your help! I aprpeciate it very much.
Post Reply