original_string: public function get_image($pageno) {
          global $CFG;
  
          if (!$this->filename) {
              throw new \coding_exception('Attempting to generate a page image without first setting the PDF filename');
          }
  
          if (!$this->imagefolder) {
              throw new \coding_exception('Attempting to generate a page image without first specifying the image output folder');
          }
  
          if (!is_dir($this->imagefolder)) {
              throw new \coding_exception('The specified image output folder is not a valid folder');
          }
  
          $imagefile = $this->imagefolder . '/' . self::IMAGE_PAGE . $pageno . '.png';
          $generate = true;
          if (file_exists($imagefile)) {
              if (filemtime($imagefile) > filemtime($this->filename)) {
                  // Make sure the image is newer than the PDF file.
                  $generate = false;
              }
          }
  
          if ($generate) {
              // Use ghostscript to generate an image of the specified page.
              $gsexec = \escapeshellarg($CFG->pathtogs);
              $imageres = \escapeshellarg(100);
              $imagefilearg = \escapeshellarg($imagefile);
              $filename = \escapeshellarg($this->filename);
              $pagenoinc = \escapeshellarg($pageno + 1);
              $command = "$gsexec -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r$imageres -dFirstPage=$pagenoinc -dLastPage=$pagenoinc ".
                  "-dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile=$imagefilearg $filename";
  
              $output = null;
              $result = exec($command, $output);
              if (!file_exists($imagefile)) {
                  $fullerror = '<pre>'.get_string('command', 'assignfeedback_editpdf')."\n";
                  $fullerror .= $command . "\n\n";
                  $fullerror .= get_string('result', 'assignfeedback_editpdf')."\n";
                  $fullerror .= htmlspecialchars($result) . "\n\n";
                  $fullerror .= get_string('output', 'assignfeedback_editpdf')."\n";
                  $fullerror .= htmlspecialchars(implode("\n", $output)) . '</pre>';
                  throw new \moodle_exception('errorgenerateimage', 'assignfeedback_editpdf', '', $fullerror);
              }
          }
  
          return self::IMAGE_PAGE . $pageno . '.png';
      }
code: public function get_image($pageno) {
          global $CFG;
  
          if (!$this->filename) {
              throw new \coding_exception('Attempting to generate a page image without first setting the PDF filename');
          }
  
          if (!$this->imagefolder) {
              throw new \coding_exception('Attempting to generate a page image without first specifying the image output folder');
          }
  
          if (!is_dir($this->imagefolder)) {
              throw new \coding_exception('The specified image output folder is not a valid folder');
          }
  
          $imagefile = $this->imagefolder . '/' . self::IMAGE_PAGE . $pageno . '.png';
          $generate = true;
          if (file_exists($imagefile)) {
              if (filemtime($imagefile) > filemtime($this->filename)) {
                  // Make sure the image is newer than the PDF file.
                  $generate = false;
              }
          }
  
          if ($generate) {
              // Use ghostscript to generate an image of the specified page.
              $gsexec = \escapeshellarg($CFG->pathtogs);
              $imageres = \escapeshellarg(100);
              $imagefilearg = \escapeshellarg($imagefile);
              $filename = \escapeshellarg($this->filename);
              $pagenoinc = \escapeshellarg($pageno + 1);
              $command = "$gsexec -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r$imageres -dFirstPage=$pagenoinc -dLastPage=$pagenoinc ".
                  "-dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile=$imagefilearg $filename";
  
              $output = null;
              $result = exec($command, $output);
              if (!file_exists($imagefile)) {
                  $fullerror = '<pre>'.get_string('command', 'assignfeedback_editpdf')."\n";
                  $fullerror .= $command . "\n\n";
                  $fullerror .= get_string('result', 'assignfeedback_editpdf')."\n";
                  $fullerror .= htmlspecialchars($result) . "\n\n";
                  $fullerror .= get_string('output', 'assignfeedback_editpdf')."\n";
                  $fullerror .= htmlspecialchars(implode("\n", $output)) . '</pre>';
                  throw new \moodle_exception('errorgenerateimage', 'assignfeedback_editpdf', '', $fullerror);
              }
          }
  
          return self::IMAGE_PAGE . $pageno . '.png';
      }
code_tokens: public function get_image ( $ pageno ) { global $ CFG ; if ( ! $ this -> filename ) { throw new \ coding_exception ( 'Attempting to generate a page image without first setting the PDF filename' ) ; } if ( ! $ this -> imagefolder ) { throw new \ coding_exception ( 'Attempting to generate a page image without first specifying the image output folder' ) ; } if ( ! is_dir ( $ this -> imagefolder ) ) { throw new \ coding_exception ( 'The specified image output folder is not a valid folder' ) ; } $ imagefile = $ this -> imagefolder . '/' . self :: IMAGE_PAGE . $ pageno . '.png' ; $ generate = true ; if ( file_exists ( $ imagefile ) ) { if ( filemtime ( $ imagefile ) > filemtime ( $ this -> filename ) ) { // Make sure the image is newer than the PDF file. $ generate = false ; } } if ( $ generate ) { // Use ghostscript to generate an image of the specified page. $ gsexec = \ escapeshellarg ( $ CFG -> pathtogs ) ; $ imageres = \ escapeshellarg ( 100 ) ; $ imagefilearg = \ escapeshellarg ( $ imagefile ) ; $ filename = \ escapeshellarg ( $ this -> filename ) ; $ pagenoinc = \ escapeshellarg ( $ pageno + 1 ) ; $ command = "$gsexec -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r$imageres -dFirstPage=$pagenoinc -dLastPage=$pagenoinc " . "-dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile=$imagefilearg $filename" ; $ output = null ; $ result = exec ( $ command , $ output ) ; if ( ! file_exists ( $ imagefile ) ) { $ fullerror = '<pre>' . get_string ( 'command' , 'assignfeedback_editpdf' ) . "\n" ; $ fullerror .= $ command . "\n\n" ; $ fullerror .= get_string ( 'result' , 'assignfeedback_editpdf' ) . "\n" ; $ fullerror .= htmlspecialchars ( $ result ) . "\n\n" ; $ fullerror .= get_string ( 'output' , 'assignfeedback_editpdf' ) . "\n" ; $ fullerror .= htmlspecialchars ( implode ( "\n" , $ output ) ) . '</pre>' ; throw new \ moodle_exception ( 'errorgenerateimage' , 'assignfeedback_editpdf' , '' , $ fullerror ) ; } } return self :: IMAGE_PAGE . $ pageno . '.png' ; }
docstring: Generate an image of the specified page in the PDF
  @param int $pageno the page to generate the image of
  @throws \moodle_exception
  @throws \coding_exception
  @return string the filename of the generated image
docstring_tokens: Generate an image of the specified page in the PDF