Why use point, the processing speed is so slowly
Why use point, the processing speed is so slowly
i use imagick function point in PHP write a code to operate pixel to change image brightness.
but the processing speed surprisingly slow ! Need several minutes to estimate ! Just like the browser collapsed !
but if use imagick to resize image or add Text on image ... and so on
these common functions are very quickly !
i don't know why ? please help me !!!!!!!!!!!!!!
----------------------------------------------------------------------------------------------------------------------
<?php
$im = new Imagick($src);
$imgSize = $im->getImageGeometry();
$w = $imgSize["width"];
$h = $imgSize["height"];
$image = new Imagick($src);
$image->newImage($w, $h, "transparent");
$draw = new ImagickDraw();
for($y=0; $y<50; $y++){
for($x=0; $x<$w; $x++) {
$p = $im->getImagePixelColor($x, $y);
//i deleted the code for change brightness for the code looks shortly
$draw->setFillColor($p);
$draw->point($x, $y); //use point to redraw image Pixel
}
}
$image->drawImage($draw);
$image->setImageFormat('jpeg');
header('Content-type: image/jpeg');
echo $image;
destroy($image);
?>
but the processing speed surprisingly slow ! Need several minutes to estimate ! Just like the browser collapsed !
but if use imagick to resize image or add Text on image ... and so on
these common functions are very quickly !
i don't know why ? please help me !!!!!!!!!!!!!!
----------------------------------------------------------------------------------------------------------------------
<?php
$im = new Imagick($src);
$imgSize = $im->getImageGeometry();
$w = $imgSize["width"];
$h = $imgSize["height"];
$image = new Imagick($src);
$image->newImage($w, $h, "transparent");
$draw = new ImagickDraw();
for($y=0; $y<50; $y++){
for($x=0; $x<$w; $x++) {
$p = $im->getImagePixelColor($x, $y);
//i deleted the code for change brightness for the code looks shortly
$draw->setFillColor($p);
$draw->point($x, $y); //use point to redraw image Pixel
}
}
$image->drawImage($draw);
$image->setImageFormat('jpeg');
header('Content-type: image/jpeg');
echo $image;
destroy($image);
?>
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Why use point, the processing speed is so slowly
Using any interpreted language to loop through all the pixels, one by one, will be slow. For interpreted languages, always use a higher-level process that acts on the entire image in a single command.
If you must do processing pixel-by-pixel, use a compiled language.
If you must do processing pixel-by-pixel, use a compiled language.
snibgo's IM pages: im.snibgo.com
Re: Why use point, the processing speed is so slowly
Thanks snibgo I have a little understandsnibgo wrote:If you must do processing pixel-by-pixel, use a compiled language.
but my programming technology is little superficial hehe
so how should I do in the PHP procedure ,
is use of PHP function to call ImagickMagick command line In order to realize this goal ? ????
can U give some suggestions ?
thanks thanks thanks
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Why use point, the processing speed is so slowly
I am not much of a programmer, but it looks like all you are doing is cropping a subsection from an image and making it into a new image.
see
http://us3.php.net/manual/en/imagick.cropimage.php
see
http://us3.php.net/manual/en/imagick.cropimage.php
Re: Why use point, the processing speed is so slowly
My thoughts was pixel-to-pixel rewrite a image ,fmw42 wrote:to fmw42 Not the corpImage
Although it looks like the corpImage , but it could change any pixels color !
snibgo tould : use a compiled language. i think he is right ! hehe
i just don't know how to use in PHP code ??
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Why use point, the processing speed is so slowly
The whole point of Imagemagick is to avoid your having to process pixel-by-pixel on your own. Imagemagick has compiled code to do most of the things you want to do to process images. So they take care of the pixel-to-pixel processing. You just have to find the right method to do what you want.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Why use point, the processing speed is so slowly
I think webwudi wants to apply change the brightness of pixels within a certain rectangle (the entire image width, but just the first 50 lines). For example, at the command line (Windows BAT syntax):
I don't know how to do this in PHP.
Code: Select all
convert ^
in.png ^
-region x50 ^
-brightness-contrast 30 ^
out.png
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Why use point, the processing speed is so slowly
As far as I know (though I am not an Imagick expert), Imagick has no equivalent to -region or -brightness-contrast. However, the something like the latter can be achieved by using either http://us3.php.net/manual/en/imagick.levelimage.php or http://us3.php.net/manual/en/imagick.si ... timage.php. To work on a subsection, one would have to use http://us3.php.net/manual/en/imagick.cropimage.php, then use one either levelImage or sigmoidalcontrastImage to make the brightness contrast adjustments, the composite the modified subsection back into the original to make the output using http://us3.php.net/manual/en/imagick.compositeimage.php
Note that Imagick is not as well supported, nor as fully functional as Imagemagick. So you may want to just use PHP exec() to run Imagemagick commands such as the one provided by user snibgo.
Note that Imagick is not as well supported, nor as fully functional as Imagemagick. So you may want to just use PHP exec() to run Imagemagick commands such as the one provided by user snibgo.
Re: Why use point, the processing speed is so slowly
ThankS although I know this comand !~snibgo wrote:to snibgo :
perhaps my thoughts was strange,
But if U think :
if U don't want change the whole image brightness but just only want change a local of the image brightness !!!
In this case, you cannot use a simple command to realize it
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Why use point, the processing speed is so slowly
snibgo's command allows you to change the brightness only is a small rectangular region. Imagemagick has other masking operations to do it in an irregular region.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Why use point, the processing speed is so slowly
As Fred says, use a mask. Examples, where m.png is black/white mask:
Code: Select all
convert ^
in.png ^
-mask m.png ^
-brightness-contrast 50 ^
+mask ^
bm.png
convert ^
in.png ^
-mask m.png ^
+level 90%%,100%% ^
+mask ^
bm2.png
convert ^
in.png ^
( +clone ^
+level 90%%,100%% ^
) ^
+swap ^
m.png ^
-composite ^
bm3.png
snibgo's IM pages: im.snibgo.com