CrimpJiggler Posted December 28, 2013 Share Posted December 28, 2013 I made this tool: http://chemistryhelper.eu.pn/ with PHP and what I need it to be able to do now is to make some of the lobes grow or shrink. How I made this script is there is one script which loads single lobes from png and arranges them into a row like this: then a second script loads the first one, and arranges the rows into a stack like this: so I need to figure out how to make single lobes grow or shrink. Heres the script which loads the single lobes: mb_language('uni'); mb_internal_encoding('UTF-8'); header ("Content-type: image/png"); $handle = ImageCreate ($this->img_width, $this->img_height) or die ("Cannot Create image"); imagesetthickness($handle,3); $lobe['color_one']['positive'] = imagecreatefrompng("$lobe_dir/lobe_u_$colors[0].png"); $lobe['color_one']['negative'] = imagecreatefrompng("$lobe_dir/lobe_d_$colors[0].png"); $lobe['color_two']['positive'] = imagecreatefrompng("$lobe_dir/lobe_u_$colors[1].png"); $lobe['color_two']['negative'] = imagecreatefrompng("$lobe_dir/lobe_d_$colors[1].png"); $bg_color = ImageColorAllocate ($handle, 255, 255, 255); $line_color = ImageColorAllocate ($handle, 0, 0, 0); ImageLine($handle, $line_coords['x']['start'], $line_y_position, $line_coords['x']['end'], $line_y_position, $line_color); // merge the two images $lobe_y_offset = 28; $height = $line_y_position - $lobe_y_offset; $low = $line_y_position + 2; $lobe_start = $line_coords['x']['start']; $increment = ($line_coords['x']['width'] / $this->lobe_num); for ($i=0; $i<$this->lobe_num; $i++) { $lobe_x_position = $lobe_start + ( $increment * $i ) + ( $increment / 4.2 ); imagecopy($handle, $top_lobe, $lobe_x_position, $height, 0, 0, imagesx($top_lobe), imagesy($top_lobe)); imagecopy($handle, $bottom_lobe, $lobe_x_position, $low, 0, 0, imagesx($bottom_lobe), imagesy($bottom_lobe)); } I removed a lot of code to make it quick to read, thats basically the part of the code which makes the straight line and adds 2 rows of lobes above and below it. To scale the lobes, I tried this: $percent = 0.5; // Get new sizes list($width, $height) = getimagesize("$lobe_dir/lobe_u_$colors[0].png"); $newwidth = $width * $percent; $newheight = $height * $percent; // Load $thumb = imagecreatetruecolor($newwidth, $newheight); $lobe['color_one']['positive'] = imagecreatefrompng("$lobe_dir/lobe_u_$colors[0].png"); $lobe['color_one']['negative'] = imagecreatefrompng("$lobe_dir/lobe_d_$colors[0].png"); $lobe['color_two']['positive'] = imagecreatefrompng("$lobe_dir/lobe_u_$colors[1].png"); $lobe['color_two']['negative'] = imagecreatefrompng("$lobe_dir/lobe_d_$colors[1].png"); imagecopyresized($thumb, $lobe['color_one']['positive'], 0, 0, 0, 0, $newwidth, $newheight, $width, $height); that should shrink one of the type of lobes to half its size, but it doesn't work, it doesn't change the size at all. Link to comment https://forums.phpfreaks.com/topic/284946-gd-library-how-to-scale-imported-image/ Share on other sites More sharing options...
CrimpJiggler Posted December 28, 2013 Author Share Posted December 28, 2013 I figured out the first problem, so heres my second issue. I need to make the backgrounds of the lobes transparent, so I added this code: imagealphablending($lobe['green']['negative'], true); // setting alpha blending on imagesavealpha($lobe['green']['negative'], true); and the problem is when I use a lobe with a transparent background, bugs start happening like this: those lobes aren't supposed to be gray. I have no idea how that can even happen. Link to comment https://forums.phpfreaks.com/topic/284946-gd-library-how-to-scale-imported-image/#findComment-1463170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.