|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-10-16 19:45 UTC] alain at ocarina dot fr
Description:
------------
I need to remove background color of an image created using MagickImage, but there's no "imagecolorat" in the MagickImage library.
I used the "getPixelRegionIterator" instead, but it makes Apache2 to crash when accessing "getColor" of the first MagickPixel object of the resulting row.
This bug is quite simple to reproduce and does not need an image, the test script above "just crashes well".
Good luck for debugging :-)
Test script:
---------------
$width = 320;
$height = 240;
$im = new Imagick();
$im->newimage($width, $height, '#000000');
$im->setImageMatte(true);
$im->unsharpMaskImage(0 , 0.5 , 1 , 0.05);
$im->normalizeImage();
$corners = new STDClass();
$corners->TL = $im->getPixelRegionIterator(0, 0, 1, 1)->getNextIteratorRow();
$corners->TL = $corners->TL[0]->getColor();
var_dump($corners);
Expected result:
----------------
object(stdClass)#3 (4) {
["TL"]=>
array(4) {
["r"]=>
int(0)
["g"]=>
int(0)
["b"]=>
int(0)
["a"]=>
int(0)
}
}
Actual result:
--------------
syslog :
Oct 16 21:34:17 KolyMac com.apple.ReportCrash.Root[65501]: 2011-10-16 21:34:17.855 ReportCrash[65501:1407] Saved crash report for httpd[65463] version ??? (???) to /Library/Logs/DiagnosticReports/httpd_2011-10-16-213417_localhost.crash
/Library/Logs/DiagnosticReports/httpd_2011-10-16-213417_localhost.crash (only backtrace) :
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libSystem.B.dylib 0x00007fff8356c9ce __semwait_signal_noca
ncel + 101 libSystem.B.dylib 0x00007fff8356c8d0 nanosleep$NOCANCEL +
1292 libSystem.B.dylib 0x00007fff835c93ce usleep$NOCANCEL + 57
3 libSystem.B.dylib 0x00007fff835e8a00 abort + 93
4 libSystem.B.dylib 0x00007fff835d59bc __pthread_markcancel + 0
5 libMagickWand.4.dylib 0x0000000101ceeff8 PixelGetRed + 1686 imagick.so 0x0000000101bbfca7 zim_imagickpixel_getc
olor + 87
7 libphp5.so 0x000000010127e66a zend_do_fcall_common_
helper_SPEC + 29868 libphp5.so 0x000000010125284b execute + 491
9 libphp5.so 0x000000010122a7ab zend_execute_scripts + 363
10 libphp5.so 0x00000001011d2382 php_execute_script + 482
11 libphp5.so 0x00000001012baa8c php_handler + 1660
12 httpd 0x00000001000016fb ap_run_handler + 123
13 httpd 0x000000010000359d ap_invoke_handler + 141
14 httpd 0x0000000100025368 ap_process_request + 440
15 httpd 0x0000000100021e98 ap_process_http_connection + 344
16 httpd 0x000000010000ee6b ap_run_process_connection + 123
17 httpd 0x000000010002a14d child_main + 957
18 httpd 0x000000010002a40a make_child + 266
19 httpd 0x000000010002ad0c ap_mpm_run + 2092
20 httpd 0x0000000100008098 main + 2328
21 httpd 0x00000001000012d4 start + 52
Thread 1:
0 libSystem.B.dylib 0x00007fff83534a6a __semwait_signal + 10
1 libSystem.B.dylib 0x00007fff83538881 _pthread_cond_wait + 1286
2 libMagickCore.4.dylib 0x0000000101f0ac4b gomp_sem_wait + 75
3 libMagickCore.4.dylib 0x0000000101f0acff gomp_barrier_wait_end + 143
4 libMagickCore.4.dylib 0x0000000101f0a3bd gomp_thread_start + 333
5 libSystem.B.dylib 0x00007fff83532fd6 _pthread_start + 331
6 libSystem.B.dylib 0x00007fff83532e89 thread_start + 13
Thread 0 crashed with X86 Thread State (64-bit):
rax: 0x000000000000003c rbx: 0x00007fff5fbfea00 rcx: 0x00007fff5fbfe9b8 rdx: 0x0000000000000001
rdi: 0x0000000000000803 rsi: 0x0000000000000000 rbp: 0x00007fff5fbfe9f0 rsp: 0x00007fff5fbfe9b8
r8: 0x0000000000000000 r9: 0x0000000000989680 r10: 0x0000000000000001 r11: 0x0000000000000246
r12: 0x0000000000000000 r13: 0x0000000101d08429 r14: 0x0000000101d02cc0 r15: 0x00007fff7056c790
rip: 0x00007fff8356c9ce rfl: 0x0000000000000247 cr2: 0x0000000122afa000
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 17:00:01 2025 UTC |
Later, that very same decade.... The issue is that Imagick should be returning an 'AreaPixelIterator' object from getPixelRegionIterator, and a RowPixelIterator when you iterate over that. But instead it just returns a pixel object from both apparently, which leads to confusion. The code below works and gives the result you were trying to do. I don't think the code will be changed before a new major version of Imagick, but the documentation needs to be improved to show how to use this function properly. <?php $width = 320; $height = 240; $im = new Imagick(); $im->newimage($width, $height, '#000000'); $im->setImageMatte(true); $im->unsharpMaskImage(0 , 0.5 , 1 , 0.05); $im->normalizeImage(); $areaIterator = $im->getPixelRegionIterator(0, 0, 1, 1); $count = 0; foreach ($areaIterator as $rowIterator) { foreach ($rowIterator as $pixel) { var_dump($pixel->getColor()); } $areaIterator->syncIterator(); }