$finalOutput = $brokenText[$i]; $textHeight += 13; } //if this is the last word append this also.The previous if will be true if the last word will have no room if ($i == count($brokenText) - 1) { $dimensions = $this->GetFontPlacementCoordinates($finalOutput, 10); $locx = $this->getHorizontalTextAlignment($this->imgSize[0], $dimensions[4]); $this->PlaceTextOnImage($this->im, 10, $locx, $textHeight, $this->font, $finalOutput); } } return $finalOutput; } public function processImg() { if ($this->lowerText != "") { $this->WorkOnImage($this->lowerText, 30, "lower"); } if ($this->upperText != "") { $this->WorkOnImage($this->upperText, 30, "upper"); } imagejpeg($this->im, "abc.jpg"); imagedestroy($this->im); echo "abc.jpg"; } } $obj = new MemeGenerator('testing.jpg'); $upmsg = $_GET['upmsg']; $downmsg = $_GET['downmsg']; $obj->setUpperText($upmsg); $obj->setLowerText($downmsg); $obj->processImg();