Make an image transparent (based on the specified RGB color range. But in practice, the following code value is removed from white. What is the problem? {Code...} transparency of an image (based on the specified RGB color range. But in practice, the following code value is removed from white. What is the problem?
$ O_pic = '1.jpg '; // The starting Color Order to be processed $ begin_r = 215; $ begin_g = 215; $ begin_ B = 215; list ($ src_w, $ src_h, $ src_type) = getimagesize ($ o_pic); // get the original image information $ file_ext = get_ext ($ o_pic); // get the extension $ target_im = imagecreatetruecolor ($ src_w, $ src_h ); // new image if ($ file_ext = 'jpg ') // convert jpg to start {$ src_im = ImageCreateFromJPEG ($ o_pic); imagecopymerge ($ target_im, $ src_im, 0, 0, 0, 0, 0, $ src_w, $ src_h, 100); for ($ x = 0; $ x <$ src_w; $ x ++) {for ($ y = 0; $ y <$ src_h; $ y ++) {$ rgb = imagecolorat ($ src_im, $ x, $ y); $ r = ($ rgb> 16) & 0xFF; $ g = ($ rgb> 8) & 0xFF; $ B = $ rgb & 0xFF; if ($ r> $ begin_r & $ g> $ begin_g & $ B> $ begin_ B) {imagecolortransparent ($ target_im, imagecolorallocate ($ target_im, $ r, $ g, $ B ));}}}}
Reply content:
Make an image transparent (based on the specified RGB color range. But in practice, the following code value is removed from white. What is the problem?
$ O_pic = '1.jpg '; // The starting Color Order to be processed $ begin_r = 215; $ begin_g = 215; $ begin_ B = 215; list ($ src_w, $ src_h, $ src_type) = getimagesize ($ o_pic); // get the original image information $ file_ext = get_ext ($ o_pic); // get the extension $ target_im = imagecreatetruecolor ($ src_w, $ src_h ); // new image if ($ file_ext = 'jpg ') // convert jpg to start {$ src_im = ImageCreateFromJPEG ($ o_pic); imagecopymerge ($ target_im, $ src_im, 0, 0, 0, 0, 0, $ src_w, $ src_h, 100); for ($ x = 0; $ x <$ src_w; $ x ++) {for ($ y = 0; $ y <$ src_h; $ y ++) {$ rgb = imagecolorat ($ src_im, $ x, $ y); $ r = ($ rgb> 16) & 0xFF; $ g = ($ rgb> 8) & 0xFF; $ B = $ rgb & 0xFF; if ($ r> $ begin_r & $ g> $ begin_g & $ B> $ begin_ B) {imagecolortransparent ($ target_im, imagecolorallocate ($ target_im, $ r, $ g, $ B ));}}}}
Do not use jpg. Because jpg does not support transparency, it is white. Use imagecreatetruecolor or imagecreatefrompng.