Rails + Amcharts (مع نص تصدير PHP Script) - تم تحويل البرنامج النصي PHP إلى وحدة تحكم؟

StackOverflow https://stackoverflow.com/questions/2569346

  •  24-09-2019
  •  | 
  •  

سؤال

هذا قد يكون مربكا بعض الشيء. أنا أستخدم amcharts مع القضبان. يأتي Amcharts مع نص PHP لتصدير الصور بعنوان "export.php"

أحاول معرفة كيفية أخذ الكود في export.php ووضعه في وحدة تحكم.

هنا هو الرمز:

   <?php
// amcharts.com export to image utility
// set image type (gif/png/jpeg)
$imgtype = 'jpeg';

// set image quality (from 0 to 100, not applicable to gif)
$imgquality = 100;

// get data from $_POST or $_GET ?
$data = &$_POST;

// get image dimensions
$width  = (int) $data['width'];
$height = (int) $data['height'];

// create image object
$img = imagecreatetruecolor($width, $height);

// populate image with pixels
for ($y = 0; $y < $height; $y++) {
  // innitialize
  $x = 0;

  // get row data
  $row = explode(',', $data['r'.$y]);

  // place row pixels
  $cnt = sizeof($row);
  for ($r = 0; $r < $cnt; $r++) {
    // get pixel(s) data
    $pixel = explode(':', $row[$r]);

    // get color
    $pixel[0] = str_pad($pixel[0], 6, '0', STR_PAD_LEFT);
    $cr = hexdec(substr($pixel[0], 0, 2));
    $cg = hexdec(substr($pixel[0], 2, 2));
    $cb = hexdec(substr($pixel[0], 4, 2));

    // allocate color
    $color = imagecolorallocate($img, $cr, $cg, $cb);

    // place repeating pixels
    $repeat = isset($pixel[1]) ? (int) $pixel[1] : 1;
    for ($c = 0; $c < $repeat; $c++) {
      // place pixel
      imagesetpixel($img, $x, $y, $color);

      // iterate column
      $x++;
    }
  }
}

// set proper content type
header('Content-type: image/'.$imgtype);
header('Content-Disposition: attachment; filename="chart.'.$imgtype.'"');

// stream image
$function = 'image'.$imgtype;
if ($imgtype == 'gif') {
  $function($img);
}
else {
  $function($img, null, $imgquality);
}

// destroy
imagedestroy($img);
?>

هناك بعض الإصدارات الموجودة في موضوع وجدته هنا: http://www.amcharts.com/forum/viewtopic.php؟id=341

لكن لدي شعور بأن رمز PHP أعلاه قد تغير منذ ذلك الحين - لأنه لم ينجح أي من التنفيذ بالنسبة لي.

هل كانت مفيدة؟

المحلول 2

لذلك يبدو أنني كنت أواجه أخطاء أخرى جعلتني أعتقد أن الكود الموجود بالفعل لم ينجح. ومع ذلك ، فإن الرمز الموجود على الموضوع الذي ربطته في السؤال الأصلي يعمل في الواقع!

نصائح أخرى

ما هذا الرمز أكثر أو أقل هو الاستيلاء على المعلومات ، التي تم إرسالها إلى البرنامج النصي (post). تتضمن المعلومات ارتفاع وعرض الصورة وقيم RGB لكل بكسل. يرسم البرنامج النصي كل بكسل ويرسل الصور في النهاية إلى العميل.

يمكنك استخدام طريقة Rmagick لرسم بكسل. هذا سوف يعطيك نفس النتيجة.

يبدو أن بيانات النشر غير المتوفرة هكذا:

height = number -> cast to int
width = number -> cast to int
// first row with a repeating part of R:G:B,R:G:B,... (n = width)
r0 = 255:0:0,150:120:0,77:88:99,...
r1 = ...
.
.
r100 = ... -> the row count is the height - 1

في الواقع ، لقد وجدت أ نقاش حول تسريع بكسل عن طريق رسم بكسل.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top