Jump to content

Recommended Posts

So I am still working on a basic advert; still got to do some tweaking, but have ran into a kind of weird situation. I set the base GD image's ($im) height to 2550; then I started adding images with imagecopymerge(). Well... I realized that I needed to re-size my images because they were taking up to much space and making my base image to tall; plus the file size was getting stupid ridiculous. So... then I started using  imagecopyresized(); well all went well until about the 6th image, that I re-sized. Then; here's where the problem comes in; the 7th, 8th, and 9th image, that I re-sized, would not display at all. So I started playing around with the height of the base image and came to find out, that as I reduced the base image's height; the other 3 images displayed. I finally had to change the base height image to 1760; in order for all the images to display in the base image.

 

So has anyone ever had this to happen and is there a work around; other then reducing my re-sized images even more? I would like to be able to display all the re-sized images and still be able to make my advert taller/longer (increase the height beyond 1760); so that I can add more text as needed.

 

This is a totally different question, but while I'm here... I figure what not. I have a wordwrap()  to check to make sure the $bodyText is not overflowing in a straight line (from one side of the image to the other), but it is not wrapping the first line with the same boundries; as it's wrapping the rest of the string. The top line is extending further; then the rest of the wrapped string/lines. Does anyone have any advice about how to fix this, as well?

 

PS: I know right now; I only have "Basic Details Here" in the $bodyText variable, but in testing.... I add a very long string.

 

<?php

// set the HTTP header type to PNG
header("Content-type: image/png"); 

// set the width and height of the new image in pixels
$width = 1000;
$height = 2550;

// create a pointer to a new true colour image
$im = imagecreatetruecolor($width, $height);

// text
$mainTitle="2011 Chrystler Town And Country LX";
$bodyText="Basic Details Here";
$price="X Amount of Dollars Here";
$di="Phone: | Website: | Email: ";

// font path
$font = 'arial.ttf';

// color
$red = ImageColorAllocate($im, 255, 0, 0); 

// sets background to white
$white = ImageColorAllocate($im, 255, 255, 255); 
ImageFillToBorder($im, 0, 0, $white, $white);

// define a black colour
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 525, 100, $white);

//word wrap
$warpText = wordwrap($bodyText, 85, "\n", true);

// display text on image
imagettftext($im, 35, 0, 100, 70, $black, $font, $mainTitle);
imagettftext($im, 25, 0, 375, 2500, $red, $font, "Price = ".$price);
imagettftext($im, 14, 0, 100, 150, $black, $font, "Dealership Information: ".$di);
imagettftext($im, 14, 0, 100, 190, $black, $font, "Vehicle Description: ".$warpText); // current gd image, font size, angle, left position, top position, color, font family, text


// make a new line and add it to the image
ImageLine($im, 0, 100, 1000, 100, $black);

// draw rectangle
ImageRectangle($im, 0, 0, $width-1, $height-1, $black);

// add photos

// define urls

$pic1="2011-Chysler-Town-And-Country-LX-driver.JPG";

$pic2="2011-Chysler-Town-And-Country-LX-pass.JPG";
$pic3="2011-Chysler-Town-And-Country-LX-front.JPG";
$pic4="2011-Chysler-Town-And-Country-LX-back.JPG";
$pic5="2011-Chysler-Town-And-Country-LX-int-driver-front.JPG";
$pic6="2011-Chysler-Town-And-Country-LX-int-driver-back.JPG";
$pic7="2011-Chysler-Town-And-Country-LX-int-pass-front.JPG";
$pic8="2011-Chysler-Town-And-Country-LX-int-pass-back.JPG";
$pic9="2011-Chysler-Town-And-Country-LX-engine.JPG";

// create images

$pic1 = imagecreatefromjpeg($pic1);
$pic2 = imagecreatefromjpeg($pic2);
$pic3 = imagecreatefromjpeg($pic3);
$pic4 = imagecreatefromjpeg($pic4);
$pic5 = imagecreatefromjpeg($pic5);
$pic6 = imagecreatefromjpeg($pic6); // it will not resize & display past here
$pic7 = imagecreatefromjpeg($pic7);
$pic8 = imagecreatefromjpeg($pic8);
$pic9 = imagecreatefromjpeg($pic9);

// display photo in this image

imagecopymerge($im, $pic1, 180, 500, 0, 0, 640, 480, 100);

// resize and display photos in this image

imagecopyresized($im, $pic2, 180, 980, 0, 0, 320, 240, 640, 480);
imagecopyresized($im, $pic3, 500, 980, 0, 0, 320, 240, 640, 480);
imagecopyresized($im, $pic4, 180, 1220, 0, 0, 320, 240, 640, 480);
imagecopyresized($im, $pic5, 500, 1220, 0, 0, 320, 240, 640, 480);
imagecopyresized($im, $pic6, 180, 1460, 0, 0, 320, 240, 640, 480);
imagecopyresized($im, $pic7, 500, 1460, 0, 0, 320, 240, 640, 480); // it will not resize & display past here
imagecopyresized($im, $pic8, 180, 1700, 0, 0, 320, 240, 640, 480);
imagecopyresized($im, $pic9, 500, 1700, 0, 0, 320, 240, 640, 480);



// destroy the reference pointer to the image in memory to free up resources

ImageDestroy($pic1);
ImageDestroy($pic2);
ImageDestroy($pic3);
ImageDestroy($pic4);
ImageDestroy($pic5);
ImageDestroy($pic6);
ImageDestroy($pic7);
ImageDestroy($pic8);
ImageDestroy($pic9);


imagepng($im);
ImageDestroy($im);

?>

I guess it could be limits involving memory for those large images.

 

QuickOldCar, that's what I am thinking to, but it's only 640X480 images. I just wonder if there is a "work around" for this kind of thing.

 

as for the wordwrap:

use this:

$warpText = wordwrap($bodyText, 85, "<br />", true);

 

The "<br />" are not in the string, so it did not recognize them or it didn't understand html elements; either way... it just spit out 1 long line of text, that did not wrap lol.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.